diff options
47 files changed, 1252 insertions, 1013 deletions
diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 45397942b..000000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "docs/_themes"] - path = docs/_themes - url = git://github.com/Pylons/pylons_sphinx_theme.git diff --git a/.travis.yml b/.travis.yml index 42b3073c7..ba077d342 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ env: - TOXENV=py2-docs - TOXENV=py3-docs - TOXENV=py2-cover,py3-cover,coverage + - TOXENV=pep8 install: - travis_retry pip install tox diff --git a/CHANGES.txt b/CHANGES.txt index 471683d25..87e9f1f3a 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,5 +1,5 @@ -Next release -============ +1.6 (2015-04-14) +================ Features -------- @@ -191,6 +191,10 @@ Bug Fixes - Avoiding timing attacks against CSRF tokens. See https://github.com/Pylons/pyramid/pull/1574 +- ``request.finished_callbacks`` and ``request.response_callbacks`` now + default to an iterable instead of ``None``. It may be checked for a length + of 0. This was the behavior in 1.5. + Deprecations ------------ @@ -233,683 +237,3 @@ Scaffolds - You can now run the scaffolding func tests via ``tox py2-scaffolds`` and ``tox py3-scaffolds``. -1.5 (2014-04-08) -================ - -- Avoid crash in ``pserve --reload`` under Py3k, when iterating over possibly - mutated ``sys.modules``. - -- ``UnencryptedCookieSessionFactoryConfig`` failed if the secret contained - higher order characters. See https://github.com/Pylons/pyramid/issues/1246 - -- Fixed a bug in ``UnencryptedCookieSessionFactoryConfig`` and - ``SignedCookieSessionFactory`` where ``timeout=None`` would cause a new - session to always be created. Also in ``SignedCookieSessionFactory`` a - ``reissue_time=None`` would cause an exception when modifying the session. - See https://github.com/Pylons/pyramid/issues/1247 - -- Updated docs and scaffolds to keep in step with new 2.0 release of - ``Lingua``. This included removing all ``setup.cfg`` files from scaffolds - and documentation environments. - -1.5b1 (2014-02-08) -================== - -Features --------- - -- We no longer eagerly clear ``request.exception`` and ``request.exc_info`` in - the exception view tween. This makes it possible to inspect exception - information within a finished callback. See - https://github.com/Pylons/pyramid/issues/1223. - -1.5a4 (2014-01-28) -================== - -Features --------- - -- Updated scaffolds with new theme, fixed documentation and sample project. - -Bug Fixes ---------- - -- Depend on a newer version of WebOb so that we pull in some crucial bug-fixes - that were showstoppers for functionality in Pyramid. - -- Add a trailing semicolon to the JSONP response. This fixes JavaScript syntax - errors for old IE versions. See https://github.com/Pylons/pyramid/pull/1205 - -- Fix a memory leak when the configurator's ``set_request_property`` method was - used or when the configurator's ``add_request_method`` method was used with - the ``property=True`` attribute. See - https://github.com/Pylons/pyramid/issues/1212 . - -1.5a3 (2013-12-10) -================== - -Features --------- - -- An authorization API has been added as a method of the - request: ``request.has_permission``. - - ``request.has_permission`` is a method-based alternative to the - ``pyramid.security.has_permission`` API and works exactly the same. The - older API is now deprecated. - -- Property API attributes have been added to the request for easier access to - authentication data: ``request.authenticated_userid``, - ``request.unauthenticated_userid``, and ``request.effective_principals``. - - These are analogues, respectively, of - ``pyramid.security.authenticated_userid``, - ``pyramid.security.unauthenticated_userid``, and - ``pyramid.security.effective_principals``. They operate exactly the same, - except they are attributes of the request instead of functions accepting a - request. They are properties, so they cannot be assigned to. The older - function-based APIs are now deprecated. - -- Pyramid's console scripts (``pserve``, ``pviews``, etc) can now be run - directly, allowing custom arguments to be sent to the python interpreter - at runtime. For example:: - - python -3 -m pyramid.scripts.pserve development.ini - -- Added a specific subclass of ``HTTPBadRequest`` named - ``pyramid.exceptions.BadCSRFToken`` which will now be raised in response - to failures in ``check_csrf_token``. - See https://github.com/Pylons/pyramid/pull/1149 - -- Added a new ``SignedCookieSessionFactory`` which is very similar to the - ``UnencryptedCookieSessionFactoryConfig`` but with a clearer focus on signing - content. The custom serializer arguments to this function should only focus - on serializing, unlike its predecessor which required the serializer to also - perform signing. See https://github.com/Pylons/pyramid/pull/1142 . Note - that 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. - -- Added a new ``BaseCookieSessionFactory`` which acts as a generic cookie - factory that can be used by framework implementors to create their own - session implementations. It provides a reusable API which focuses strictly - on providing a dictionary-like object that properly handles renewals, - timeouts, and conformance with the ``ISession`` API. - See https://github.com/Pylons/pyramid/pull/1142 - -- The anchor argument to ``pyramid.request.Request.route_url`` and - ``pyramid.request.Request.resource_url`` and their derivatives will now be - escaped via URL quoting to ensure minimal conformance. See - https://github.com/Pylons/pyramid/pull/1183 - -- Allow sending of ``_query`` and ``_anchor`` options to - ``pyramid.request.Request.static_url`` when an external URL is being - generated. - See https://github.com/Pylons/pyramid/pull/1183 - -- You can now send a string as the ``_query`` argument to - ``pyramid.request.Request.route_url`` and - ``pyramid.request.Request.resource_url`` and their derivatives. When a - string is sent instead of a list or dictionary. it is URL-quoted however it - does not need to be in ``k=v`` form. This is useful if you want to be able - to use a different query string format than ``x-www-form-urlencoded``. See - https://github.com/Pylons/pyramid/pull/1183 - -- ``pyramid.testing.DummyRequest`` now has a ``domain`` attribute to match the - new WebOb 1.3 API. Its value is ``example.com``. - -Bug Fixes ---------- - -- Fix the ``pcreate`` script so that when the target directory name ends with a - slash it does not produce a non-working project directory structure. - Previously saying ``pcreate -s starter /foo/bar/`` produced different output - than saying ``pcreate -s starter /foo/bar``. The former did not work - properly. - -- Fix the ``principals_allowed_by_permission`` method of - ``ACLAuthorizationPolicy`` so it anticipates a callable ``__acl__`` - on resources. Previously it did not try to call the ``__acl__`` - if it was callable. - -- The ``pviews`` script did not work when a url required custom request - methods in order to perform traversal. Custom methods and descriptors added - via ``pyramid.config.Configurator.add_request_method`` will now be present, - allowing traversal to continue. - See https://github.com/Pylons/pyramid/issues/1104 - -- Remove unused ``renderer`` argument from ``Configurator.add_route``. - -- Allow the ``BasicAuthenticationPolicy`` to work with non-ascii usernames - and passwords. The charset is not passed as part of the header and different - browsers alternate between UTF-8 and Latin-1, so the policy now attempts - to decode with UTF-8 first, and will fallback to Latin-1. - See https://github.com/Pylons/pyramid/pull/1170 - -- The ``@view_defaults`` now apply to notfound and forbidden views - that are defined as methods of a decorated class. - See https://github.com/Pylons/pyramid/issues/1173 - -Documentation -------------- - -- Added a "Quick Tutorial" to go with the Quick Tour - -- Removed mention of ``pyramid_beaker`` from docs. Beaker is no longer - maintained. Point people at ``pyramid_redis_sessions`` instead. - -- Add documentation for ``pyramid.interfaces.IRendererFactory`` and - ``pyramid.interfaces.IRenderer``. - -Backwards Incompatibilities ---------------------------- - -- The key/values in the ``_query`` parameter of ``request.route_url`` and the - ``query`` parameter of ``request.resource_url`` (and their variants), used - to encode a value of ``None`` as the string ``'None'``, leaving the resulting - query string to be ``a=b&key=None``. The value is now dropped in this - situation, leaving a query string of ``a=b&key=``. - See https://github.com/Pylons/pyramid/issues/1119 - -Deprecations ------------- - -- Deprecate the ``pyramid.interfaces.ITemplateRenderer`` interface. It was - ill-defined and became unused when Mako and Chameleon template bindings were - split into their own packages. - -- The ``pyramid.session.UnencryptedCookieSessionFactoryConfig`` API has been - deprecated and is superseded by the - ``pyramid.session.SignedCookieSessionFactory``. Note that while the cookies - generated by the ``UnencryptedCookieSessionFactoryConfig`` - are compatible with cookies generated by old releases, cookies generated by - the SignedCookieSessionFactory are not. See - https://github.com/Pylons/pyramid/pull/1142 - -- The ``pyramid.security.has_permission`` API is now deprecated. Instead, use - the newly-added ``has_permission`` method of the request object. - -- The ``pyramid.security.effective_principals`` API is now deprecated. - Instead, use the newly-added ``effective_principals`` attribute of the - request object. - -- The ``pyramid.security.authenticated_userid`` API is now deprecated. - Instead, use the newly-added ``authenticated_userid`` attribute of the - request object. - -- The ``pyramid.security.unauthenticated_userid`` API is now deprecated. - Instead, use the newly-added ``unauthenticated_userid`` attribute of the - request object. - -Dependencies ------------- - -- Pyramid now depends on WebOb>=1.3 (it uses ``webob.cookies.CookieProfile`` - from 1.3+). - -1.5a2 (2013-09-22) -================== - -Features --------- - -- Users can now provide dotted Python names to as the ``factory`` argument - the Configurator methods named ``add_{view,route,subscriber}_predicate`` - (instead of passing the predicate factory directly, you can pass a - dotted name which refers to the factory). - -Bug Fixes ---------- - -- Fix an exception in ``pyramid.path.package_name`` when resolving the package - name for namespace packages that had no ``__file__`` attribute. - -Backwards Incompatibilities ---------------------------- - -- Pyramid no longer depends on or configures the Mako and Chameleon templating - system renderers by default. Disincluding these templating systems by - default means that the Pyramid core has fewer dependencies and can run on - future platforms without immediate concern for the compatibility of its - templating add-ons. It also makes maintenance slightly more effective, as - different people can maintain the templating system add-ons that they - understand and care about without needing commit access to the Pyramid core, - and it allows users who just don't want to see any packages they don't use - come along for the ride when they install Pyramid. - - This means that upon upgrading to Pyramid 1.5a2+, projects that use either - of these templating systems will see a traceback that ends something like - this when their application attempts to render a Chameleon or Mako template:: - - ValueError: No such renderer factory .pt - - Or:: - - ValueError: No such renderer factory .mako - - Or:: - - ValueError: No such renderer factory .mak - - Support for Mako templating has been moved into an add-on package named - ``pyramid_mako``, and support for Chameleon templating has been moved into - an add-on package named ``pyramid_chameleon``. These packages are drop-in - replacements for the old built-in support for these templating langauges. - All you have to do is install them and make them active in your configuration - to register renderer factories for ``.pt`` and/or ``.mako`` (or ``.mak``) to - make your application work again. - - To re-add support for Chameleon and/or Mako template renderers into your - existing projects, follow the below steps. - - If you depend on Mako templates: - - * Make sure the ``pyramid_mako`` package is installed. One way to do this - is by adding ``pyramid_mako`` to the ``install_requires`` section of your - package's ``setup.py`` file and afterwards rerunning ``setup.py develop``:: - - setup( - #... - install_requires=[ - 'pyramid_mako', # new dependency - 'pyramid', - #... - ], - ) - - * Within the portion of your application which instantiates a Pyramid - ``pyramid.config.Configurator`` (often the ``main()`` function in - your project's ``__init__.py`` file), tell Pyramid to include the - ``pyramid_mako`` includeme:: - - config = Configurator(.....) - config.include('pyramid_mako') - - If you depend on Chameleon templates: - - * Make sure the ``pyramid_chameleon`` package is installed. One way to do - this is by adding ``pyramid_chameleon`` to the ``install_requires`` section - of your package's ``setup.py`` file and afterwards rerunning - ``setup.py develop``:: - - setup( - #... - install_requires=[ - 'pyramid_chameleon', # new dependency - 'pyramid', - #... - ], - ) - - * Within the portion of your application which instantiates a Pyramid - ``~pyramid.config.Configurator`` (often the ``main()`` function in - your project's ``__init__.py`` file), tell Pyramid to include the - ``pyramid_chameleon`` includeme:: - - config = Configurator(.....) - config.include('pyramid_chameleon') - - Note that it's also fine to install these packages into *older* Pyramids for - forward compatibility purposes. Even if you don't upgrade to Pyramid 1.5 - immediately, performing the above steps in a Pyramid 1.4 installation is - perfectly fine, won't cause any difference, and will give you forward - compatibility when you eventually do upgrade to Pyramid 1.5. - - With the removal of Mako and Chameleon support from the core, some - unit tests that use the ``pyramid.renderers.render*`` methods may begin to - fail. If any of your unit tests are invoking either - ``pyramid.renderers.render()`` or ``pyramid.renderers.render_to_response()`` - with either Mako or Chameleon templates then the - ``pyramid.config.Configurator`` instance in effect during - the unit test should be also be updated to include the addons, as shown - above. For example:: - - class ATest(unittest.TestCase): - def setUp(self): - self.config = pyramid.testing.setUp() - self.config.include('pyramid_mako') - - def test_it(self): - result = pyramid.renderers.render('mypkg:templates/home.mako', {}) - - Or:: - - class ATest(unittest.TestCase): - def setUp(self): - self.config = pyramid.testing.setUp() - self.config.include('pyramid_chameleon') - - def test_it(self): - result = pyramid.renderers.render('mypkg:templates/home.pt', {}) - -- If you're using the Pyramid debug toolbar, when you upgrade Pyramid to - 1.5a2+, you'll also need to upgrade the ``pyramid_debugtoolbar`` package to - at least version 1.0.8, as older toolbar versions are not compatible with - Pyramid 1.5a2+ due to the removal of Mako support from the core. It's - fine to use this newer version of the toolbar code with older Pyramids too. - -- Removed the ``request.response_*`` varying attributes. These attributes - have been deprecated since Pyramid 1.1, and as per the deprecation policy, - have now been removed. - -- ``request.response`` will no longer be mutated when using the - ``pyramid.renderers.render()`` API. Almost all renderers mutate the - ``request.response`` response object (for example, the JSON renderer sets - ``request.response.content_type`` to ``application/json``), but this is - only necessary when the renderer is generating a response; it was a bug - when it was done as a side effect of calling ``pyramid.renderers.render()``. - -- Removed the ``bfg2pyramid`` fixer script. - -- The ``pyramid.events.NewResponse`` event is now sent **after** response - callbacks are executed. It previously executed before response callbacks - were executed. Rationale: it's more useful to be able to inspect the response - after response callbacks have done their jobs instead of before. - -- Removed the class named ``pyramid.view.static`` that had been deprecated - since Pyramid 1.1. Instead use ``pyramid.static.static_view`` with - ``use_subpath=True`` argument. - -- Removed the ``pyramid.view.is_response`` function that had been deprecated - since Pyramid 1.1. Use the ``pyramid.request.Request.is_response`` method - instead. - -- Removed the ability to pass the following arguments to - ``pyramid.config.Configurator.add_route``: ``view``, ``view_context``. - ``view_for``, ``view_permission``, ``view_renderer``, and ``view_attr``. - Using these arguments had been deprecated since Pyramid 1.1. Instead of - passing view-related arguments to ``add_route``, use a separate call to - ``pyramid.config.Configurator.add_view`` to associate a view with a route - using its ``route_name`` argument. Note that this impacts the - ``pyramid.config.Configurator.add_static_view`` function too, because it - delegates to ``add_route``. - -- Removed the ability to influence and query a ``pyramid.request.Request`` - object as if it were a dictionary. Previously it was possible to use methods - like ``__getitem__``, ``get``, ``items``, and other dictlike methods to - access values in the WSGI environment. This behavior had been deprecated - since Pyramid 1.1. Use methods of ``request.environ`` (a real dictionary) - instead. - -- Removed ancient backwards compatibily hack in - ``pyramid.traversal.DefaultRootFactory`` which populated the ``__dict__`` of - the factory with the matchdict values for compatibility with BFG 0.9. - -- The ``renderer_globals_factory`` argument to the - ``pyramid.config.Configurator` constructor and its ``setup_registry`` method - has been removed. The ``set_renderer_globals_factory`` method of - ``pyramid.config.Configurator`` has also been removed. The (internal) - ``pyramid.interfaces.IRendererGlobals`` interface was also removed. These - arguments, methods and interfaces had been deprecated since 1.1. Use a - ``BeforeRender`` event subscriber as documented in the "Hooks" chapter of the - Pyramid narrative documentation instead of providing renderer globals values - to the configurator. - -Deprecations ------------- - -- The ``pyramid.config.Configurator.set_request_property`` method now issues - a deprecation warning when used. It had been docs-deprecated in 1.4 - but did not issue a deprecation warning when used. - -1.5a1 (2013-08-30) -================== - -Features --------- - -- A new http exception subclass named ``pyramid.httpexceptions.HTTPSuccessful`` - was added. You can use this class as the ``context`` of an exception - view to catch all 200-series "exceptions" (e.g. "raise HTTPOk"). This - also allows you to catch *only* the ``HTTPOk`` exception itself; previously - this was impossible because a number of other exceptions - (such as ``HTTPNoContent``) inherited from ``HTTPOk``, but now they do not. - -- You can now generate "hybrid" urldispatch/traversal URLs more easily - by using the new ``route_name``, ``route_kw`` and ``route_remainder_name`` - arguments to ``request.resource_url`` and ``request.resource_path``. See - the new section of the "Combining Traversal and URL Dispatch" documentation - chapter entitled "Hybrid URL Generation". - -- It is now possible to escape double braces in Pyramid scaffolds (unescaped, - these represent replacement values). You can use ``\{\{a\}\}`` to - represent a "bare" ``{{a}}``. See - https://github.com/Pylons/pyramid/pull/862 - -- Add ``localizer`` and ``locale_name`` properties (reified) to the request. - See https://github.com/Pylons/pyramid/issues/508. Note that the - ``pyramid.i18n.get_localizer`` and ``pyramid.i18n.get_locale_name`` functions - now simply look up these properties on the request. - -- 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. - -- Add the ability to invert the result of any view, route, or subscriber - predicate using the ``not_`` class. For example:: - - from pyramid.config import not_ - - @view_config(route_name='myroute', request_method=not_('POST')) - def myview(request): ... - - The above example will ensure that the view is called if the request method - is not POST (at least if no other view is more specific). - - The ``pyramid.config.not_`` class can be used against any value that is - a predicate value passed in any of these contexts: - - - ``pyramid.config.Configurator.add_view`` - - - ``pyramid.config.Configurator.add_route`` - - - ``pyramid.config.Configurator.add_subscriber`` - - - ``pyramid.view.view_config`` - - - ``pyramid.events.subscriber`` - -- ``scripts/prequest.py``: add support for submitting ``PUT`` and ``PATCH`` - requests. See https://github.com/Pylons/pyramid/pull/1033. add support for - submitting ``OPTIONS`` and ``PROPFIND`` requests, and allow users to specify - basic authentication credentials in the request via a ``--login`` argument to - the script. See https://github.com/Pylons/pyramid/pull/1039. - -- ``ACLAuthorizationPolicy`` supports ``__acl__`` as a callable. This - removes the ambiguity between the potential ``AttributeError`` that would - be raised on the ``context`` when the property was not defined and the - ``AttributeError`` that could be raised from any user-defined code within - a dynamic property. It is recommended to define a dynamic ACL as a callable - to avoid this ambiguity. See https://github.com/Pylons/pyramid/issues/735. - -- Allow a protocol-relative URL (e.g. ``//example.com/images``) to be passed to - ``pyramid.config.Configurator.add_static_view``. This allows - externally-hosted static URLs to be generated based on the current protocol. - -- The ``AuthTktAuthenticationPolicy`` has two new options to configure its - domain usage: - - * ``parent_domain``: if set the authentication cookie is set on - the parent domain. This is useful if you have multiple sites sharing the - same domain. - * ``domain``: if provided the cookie is always set for this domain, bypassing - all usual logic. - - See https://github.com/Pylons/pyramid/pull/1028, - https://github.com/Pylons/pyramid/pull/1072 and - https://github.com/Pylons/pyramid/pull/1078. - -- The ``AuthTktAuthenticationPolicy`` now supports IPv6 addresses when using - the ``include_ip=True`` option. This is possibly incompatible with - alternative ``auth_tkt`` implementations, as the specification does not - define how to properly handle IPv6. See - https://github.com/Pylons/pyramid/issues/831. - -- Make it possible to use variable arguments via - ``pyramid.paster.get_appsettings``. This also allowed the generated - ``initialize_db`` script from the ``alchemy`` scaffold to grow support - for options in the form ``a=1 b=2`` so you can fill in - values in a parameterized ``.ini`` file, e.g. - ``initialize_myapp_db etc/development.ini a=1 b=2``. - See https://github.com/Pylons/pyramid/pull/911 - -- The ``request.session.check_csrf_token()`` method and the ``check_csrf`` view - predicate now take into account the value of the HTTP header named - ``X-CSRF-Token`` (as well as the ``csrf_token`` form parameter, which they - always did). The header is tried when the form parameter does not exist. - -- View lookup will now search for valid views based on the inheritance - hierarchy of the context. It tries to find views based on the most - specific context first, and upon predicate failure, will move up the - inheritance chain to test views found by the super-type of the context. - In the past, only the most specific type containing views would be checked - and if no matching view could be found then a PredicateMismatch would be - raised. Now predicate mismatches don't hide valid views registered on - super-types. Here's an example that now works:: - - class IResource(Interface): - - ... - - @view_config(context=IResource) - def get(context, request): - - ... - - @view_config(context=IResource, request_method='POST') - def post(context, request): - - ... - - @view_config(context=IResource, request_method='DELETE') - def delete(context, request): - - ... - - @implementer(IResource) - class MyResource: - - ... - - @view_config(context=MyResource, request_method='POST') - def override_post(context, request): - - ... - - Previously the override_post view registration would hide the get - and delete views in the context of MyResource -- leading to a - predicate mismatch error when trying to use GET or DELETE - methods. Now the views are found and no predicate mismatch is - raised. - See https://github.com/Pylons/pyramid/pull/786 and - https://github.com/Pylons/pyramid/pull/1004 and - https://github.com/Pylons/pyramid/pull/1046 - -- The ``pserve`` command now takes a ``-v`` (or ``--verbose``) flag and a - ``-q`` (or ``--quiet``) flag. Output from running ``pserve`` can be - controlled using these flags. ``-v`` can be specified multiple times to - increase verbosity. ``-q`` sets verbosity to ``0`` unconditionally. The - default verbosity level is ``1``. - -- The ``alchemy`` scaffold tests now provide better coverage. See - https://github.com/Pylons/pyramid/pull/1029 - -- The ``pyramid.config.Configurator.add_route`` method now supports being - called with an external URL as pattern. See - https://github.com/Pylons/pyramid/issues/611 and the documentation section - in the "URL Dispatch" chapter entitled "External Routes" for more information. - -Bug Fixes ---------- - -- It was not possible to use ``pyramid.httpexceptions.HTTPException`` as - the ``context`` of an exception view as very general catchall for - http-related exceptions when you wanted that exception view to override the - default exception view. See https://github.com/Pylons/pyramid/issues/985 - -- When the ``pyramid.reload_templates`` setting was true, and a Chameleon - template was reloaded, and the renderer specification named a macro - (e.g. ``foo#macroname.pt``), renderings of the template after the template - was reloaded due to a file change would produce the entire template body - instead of just a rendering of the macro. See - https://github.com/Pylons/pyramid/issues/1013. - -- Fix an obscure problem when combining a virtual root with a route with a - ``*traverse`` in its pattern. Now the traversal path generated in - such a configuration will be correct, instead of an element missing - a leading slash. - -- Fixed a Mako renderer bug returning a tuple with a previous defname value - in some circumstances. See https://github.com/Pylons/pyramid/issues/1037 - for more information. - -- Make the ``pyramid.config.assets.PackageOverrides`` object implement the API - for ``__loader__`` objects specified in PEP 302. Proxies to the - ``__loader__`` set by the importer, if present; otherwise, raises - ``NotImplementedError``. This makes Pyramid static view overrides work - properly under Python 3.3 (previously they would not). See - https://github.com/Pylons/pyramid/pull/1015 for more information. - -- ``mako_templating``: added defensive workaround for non-importability of - ``mako`` due to upstream ``markupsafe`` dropping Python 3.2 support. Mako - templating will no longer work under the combination of MarkupSafe 0.17 and - Python 3.2 (although the combination of MarkupSafe 0.17 and Python 3.3 or any - supported Python 2 version will work OK). - -- Spaces and dots may now be in mako renderer template paths. This was - broken when support for the new makodef syntax was added in 1.4a1. - See https://github.com/Pylons/pyramid/issues/950 - -- ``pyramid.debug_authorization=true`` will now correctly print out - ``Allowed`` for views registered with ``NO_PERMISSION_REQUIRED`` instead - of invoking the ``permits`` method of the authorization policy. - See https://github.com/Pylons/pyramid/issues/954 - -- Pyramid failed to install on some systems due to being packaged with - some test files containing higher order characters in their names. These - files have now been removed. See - https://github.com/Pylons/pyramid/issues/981 - -- ``pyramid.testing.DummyResource`` didn't define ``__bool__``, so code under - Python 3 would use ``__len__`` to find truthiness; this usually caused an - instance of DummyResource to be "falsy" instead of "truthy". See - https://github.com/Pylons/pyramid/pull/1032 - -- The ``alchemy`` scaffold would break when the database was MySQL during - tables creation. See https://github.com/Pylons/pyramid/pull/1049 - -- The ``current_route_url`` method now attaches the query string to the URL by - default. See - https://github.com/Pylons/pyramid/issues/1040 - -- Make ``pserve.cherrypy_server_runner`` Python 3 compatible. See - https://github.com/Pylons/pyramid/issues/718 - -Backwards Incompatibilities ---------------------------- - -- Modified the ``current_route_url`` method in pyramid.Request. The method - previously returned the URL without the query string by default, it now does - attach the query string unless it is overriden. - -- The ``route_url`` and ``route_path`` APIs no longer quote ``/`` - to ``%2F`` when a replacement value contains a ``/``. This was pointless, - as WSGI servers always unquote the slash anyway, and Pyramid never sees the - quoted value. - -- It is no longer possible to set a ``locale_name`` attribute of the request, - nor is it possible to set a ``localizer`` attribute of the request. These - are now "reified" properties that look up a locale name and localizer - respectively using the machinery described in the "Internationalization" - chapter of the documentation. - -- If you send an ``X-Vhm-Root`` header with a value that ends with a slash (or - any number of slashes), the trailing slash(es) will be removed before a URL - is generated when you use use ``request.resource_url`` or - ``request.resource_path``. Previously the virtual root path would not have - trailing slashes stripped, which would influence URL generation. - -- The ``pyramid.interfaces.IResourceURL`` interface has now grown two new - attributes: ``virtual_path_tuple`` and ``physical_path_tuple``. These should - be the tuple form of the resource's path (physical and virtual). - diff --git a/HACKING.txt b/HACKING.txt index 9a7df8679..b82041c71 100644 --- a/HACKING.txt +++ b/HACKING.txt @@ -216,29 +216,12 @@ documentation in this package which references that API or behavior must be changed to reflect the bug fix, ideally in the same commit that fixes the bug or adds the feature. To build and review docs, use the following steps. -1. After following the steps above in "Using a Development Checkout", update - all git submodules from the top-level of your Pyramid checkout, like so: +1. In the main Pyramid checkout directory, run ``./builddocs.sh`` (which just + turns around and runs ``tox -e py2-docs,py3-docs``):: - $ git submodule update --init --recursive + $ ./builddocs.sh - This will checkout theme subrepositories and prevent error conditions when - HTML docs are generated. - -2. Next change into the submodule's directory and switch to a branch so that - the submodule repositories are no longer "headless". Then update the - repository to ensure that we have the latest updates. - See http://chrisjean.com/2009/04/20/git-submodules-adding-using-removing-and-updating/ :: - - $ cd docs/_themes - $ git checkout master - $ git pull - -3. Change back to the main Pyramid checkout dir and run ``./builddocs`` (which - just turns around and runs ``tox -e py2-docs,py3-docs``):: - - $ ./builddocs - -5. Open the ``.tox/_build/html/index.html`` file to see the resulting HTML +2. Open the ``docs/_build/html/index.html`` file to see the resulting HTML rendering. Change Log diff --git a/HISTORY.txt b/HISTORY.txt index 242568e98..c30bb2711 100644 --- a/HISTORY.txt +++ b/HISTORY.txt @@ -1,3 +1,683 @@ +1.5 (2014-04-08) +================ + +- Avoid crash in ``pserve --reload`` under Py3k, when iterating over possibly + mutated ``sys.modules``. + +- ``UnencryptedCookieSessionFactoryConfig`` failed if the secret contained + higher order characters. See https://github.com/Pylons/pyramid/issues/1246 + +- Fixed a bug in ``UnencryptedCookieSessionFactoryConfig`` and + ``SignedCookieSessionFactory`` where ``timeout=None`` would cause a new + session to always be created. Also in ``SignedCookieSessionFactory`` a + ``reissue_time=None`` would cause an exception when modifying the session. + See https://github.com/Pylons/pyramid/issues/1247 + +- Updated docs and scaffolds to keep in step with new 2.0 release of + ``Lingua``. This included removing all ``setup.cfg`` files from scaffolds + and documentation environments. + +1.5b1 (2014-02-08) +================== + +Features +-------- + +- We no longer eagerly clear ``request.exception`` and ``request.exc_info`` in + the exception view tween. This makes it possible to inspect exception + information within a finished callback. See + https://github.com/Pylons/pyramid/issues/1223. + +1.5a4 (2014-01-28) +================== + +Features +-------- + +- Updated scaffolds with new theme, fixed documentation and sample project. + +Bug Fixes +--------- + +- Depend on a newer version of WebOb so that we pull in some crucial bug-fixes + that were showstoppers for functionality in Pyramid. + +- Add a trailing semicolon to the JSONP response. This fixes JavaScript syntax + errors for old IE versions. See https://github.com/Pylons/pyramid/pull/1205 + +- Fix a memory leak when the configurator's ``set_request_property`` method was + used or when the configurator's ``add_request_method`` method was used with + the ``property=True`` attribute. See + https://github.com/Pylons/pyramid/issues/1212 . + +1.5a3 (2013-12-10) +================== + +Features +-------- + +- An authorization API has been added as a method of the + request: ``request.has_permission``. + + ``request.has_permission`` is a method-based alternative to the + ``pyramid.security.has_permission`` API and works exactly the same. The + older API is now deprecated. + +- Property API attributes have been added to the request for easier access to + authentication data: ``request.authenticated_userid``, + ``request.unauthenticated_userid``, and ``request.effective_principals``. + + These are analogues, respectively, of + ``pyramid.security.authenticated_userid``, + ``pyramid.security.unauthenticated_userid``, and + ``pyramid.security.effective_principals``. They operate exactly the same, + except they are attributes of the request instead of functions accepting a + request. They are properties, so they cannot be assigned to. The older + function-based APIs are now deprecated. + +- Pyramid's console scripts (``pserve``, ``pviews``, etc) can now be run + directly, allowing custom arguments to be sent to the python interpreter + at runtime. For example:: + + python -3 -m pyramid.scripts.pserve development.ini + +- Added a specific subclass of ``HTTPBadRequest`` named + ``pyramid.exceptions.BadCSRFToken`` which will now be raised in response + to failures in ``check_csrf_token``. + See https://github.com/Pylons/pyramid/pull/1149 + +- Added a new ``SignedCookieSessionFactory`` which is very similar to the + ``UnencryptedCookieSessionFactoryConfig`` but with a clearer focus on signing + content. The custom serializer arguments to this function should only focus + on serializing, unlike its predecessor which required the serializer to also + perform signing. See https://github.com/Pylons/pyramid/pull/1142 . Note + that 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. + +- Added a new ``BaseCookieSessionFactory`` which acts as a generic cookie + factory that can be used by framework implementors to create their own + session implementations. It provides a reusable API which focuses strictly + on providing a dictionary-like object that properly handles renewals, + timeouts, and conformance with the ``ISession`` API. + See https://github.com/Pylons/pyramid/pull/1142 + +- The anchor argument to ``pyramid.request.Request.route_url`` and + ``pyramid.request.Request.resource_url`` and their derivatives will now be + escaped via URL quoting to ensure minimal conformance. See + https://github.com/Pylons/pyramid/pull/1183 + +- Allow sending of ``_query`` and ``_anchor`` options to + ``pyramid.request.Request.static_url`` when an external URL is being + generated. + See https://github.com/Pylons/pyramid/pull/1183 + +- You can now send a string as the ``_query`` argument to + ``pyramid.request.Request.route_url`` and + ``pyramid.request.Request.resource_url`` and their derivatives. When a + string is sent instead of a list or dictionary. it is URL-quoted however it + does not need to be in ``k=v`` form. This is useful if you want to be able + to use a different query string format than ``x-www-form-urlencoded``. See + https://github.com/Pylons/pyramid/pull/1183 + +- ``pyramid.testing.DummyRequest`` now has a ``domain`` attribute to match the + new WebOb 1.3 API. Its value is ``example.com``. + +Bug Fixes +--------- + +- Fix the ``pcreate`` script so that when the target directory name ends with a + slash it does not produce a non-working project directory structure. + Previously saying ``pcreate -s starter /foo/bar/`` produced different output + than saying ``pcreate -s starter /foo/bar``. The former did not work + properly. + +- Fix the ``principals_allowed_by_permission`` method of + ``ACLAuthorizationPolicy`` so it anticipates a callable ``__acl__`` + on resources. Previously it did not try to call the ``__acl__`` + if it was callable. + +- The ``pviews`` script did not work when a url required custom request + methods in order to perform traversal. Custom methods and descriptors added + via ``pyramid.config.Configurator.add_request_method`` will now be present, + allowing traversal to continue. + See https://github.com/Pylons/pyramid/issues/1104 + +- Remove unused ``renderer`` argument from ``Configurator.add_route``. + +- Allow the ``BasicAuthenticationPolicy`` to work with non-ascii usernames + and passwords. The charset is not passed as part of the header and different + browsers alternate between UTF-8 and Latin-1, so the policy now attempts + to decode with UTF-8 first, and will fallback to Latin-1. + See https://github.com/Pylons/pyramid/pull/1170 + +- The ``@view_defaults`` now apply to notfound and forbidden views + that are defined as methods of a decorated class. + See https://github.com/Pylons/pyramid/issues/1173 + +Documentation +------------- + +- Added a "Quick Tutorial" to go with the Quick Tour + +- Removed mention of ``pyramid_beaker`` from docs. Beaker is no longer + maintained. Point people at ``pyramid_redis_sessions`` instead. + +- Add documentation for ``pyramid.interfaces.IRendererFactory`` and + ``pyramid.interfaces.IRenderer``. + +Backwards Incompatibilities +--------------------------- + +- The key/values in the ``_query`` parameter of ``request.route_url`` and the + ``query`` parameter of ``request.resource_url`` (and their variants), used + to encode a value of ``None`` as the string ``'None'``, leaving the resulting + query string to be ``a=b&key=None``. The value is now dropped in this + situation, leaving a query string of ``a=b&key=``. + See https://github.com/Pylons/pyramid/issues/1119 + +Deprecations +------------ + +- Deprecate the ``pyramid.interfaces.ITemplateRenderer`` interface. It was + ill-defined and became unused when Mako and Chameleon template bindings were + split into their own packages. + +- The ``pyramid.session.UnencryptedCookieSessionFactoryConfig`` API has been + deprecated and is superseded by the + ``pyramid.session.SignedCookieSessionFactory``. Note that while the cookies + generated by the ``UnencryptedCookieSessionFactoryConfig`` + are compatible with cookies generated by old releases, cookies generated by + the SignedCookieSessionFactory are not. See + https://github.com/Pylons/pyramid/pull/1142 + +- The ``pyramid.security.has_permission`` API is now deprecated. Instead, use + the newly-added ``has_permission`` method of the request object. + +- The ``pyramid.security.effective_principals`` API is now deprecated. + Instead, use the newly-added ``effective_principals`` attribute of the + request object. + +- The ``pyramid.security.authenticated_userid`` API is now deprecated. + Instead, use the newly-added ``authenticated_userid`` attribute of the + request object. + +- The ``pyramid.security.unauthenticated_userid`` API is now deprecated. + Instead, use the newly-added ``unauthenticated_userid`` attribute of the + request object. + +Dependencies +------------ + +- Pyramid now depends on WebOb>=1.3 (it uses ``webob.cookies.CookieProfile`` + from 1.3+). + +1.5a2 (2013-09-22) +================== + +Features +-------- + +- Users can now provide dotted Python names to as the ``factory`` argument + the Configurator methods named ``add_{view,route,subscriber}_predicate`` + (instead of passing the predicate factory directly, you can pass a + dotted name which refers to the factory). + +Bug Fixes +--------- + +- Fix an exception in ``pyramid.path.package_name`` when resolving the package + name for namespace packages that had no ``__file__`` attribute. + +Backwards Incompatibilities +--------------------------- + +- Pyramid no longer depends on or configures the Mako and Chameleon templating + system renderers by default. Disincluding these templating systems by + default means that the Pyramid core has fewer dependencies and can run on + future platforms without immediate concern for the compatibility of its + templating add-ons. It also makes maintenance slightly more effective, as + different people can maintain the templating system add-ons that they + understand and care about without needing commit access to the Pyramid core, + and it allows users who just don't want to see any packages they don't use + come along for the ride when they install Pyramid. + + This means that upon upgrading to Pyramid 1.5a2+, projects that use either + of these templating systems will see a traceback that ends something like + this when their application attempts to render a Chameleon or Mako template:: + + ValueError: No such renderer factory .pt + + Or:: + + ValueError: No such renderer factory .mako + + Or:: + + ValueError: No such renderer factory .mak + + Support for Mako templating has been moved into an add-on package named + ``pyramid_mako``, and support for Chameleon templating has been moved into + an add-on package named ``pyramid_chameleon``. These packages are drop-in + replacements for the old built-in support for these templating langauges. + All you have to do is install them and make them active in your configuration + to register renderer factories for ``.pt`` and/or ``.mako`` (or ``.mak``) to + make your application work again. + + To re-add support for Chameleon and/or Mako template renderers into your + existing projects, follow the below steps. + + If you depend on Mako templates: + + * Make sure the ``pyramid_mako`` package is installed. One way to do this + is by adding ``pyramid_mako`` to the ``install_requires`` section of your + package's ``setup.py`` file and afterwards rerunning ``setup.py develop``:: + + setup( + #... + install_requires=[ + 'pyramid_mako', # new dependency + 'pyramid', + #... + ], + ) + + * Within the portion of your application which instantiates a Pyramid + ``pyramid.config.Configurator`` (often the ``main()`` function in + your project's ``__init__.py`` file), tell Pyramid to include the + ``pyramid_mako`` includeme:: + + config = Configurator(.....) + config.include('pyramid_mako') + + If you depend on Chameleon templates: + + * Make sure the ``pyramid_chameleon`` package is installed. One way to do + this is by adding ``pyramid_chameleon`` to the ``install_requires`` section + of your package's ``setup.py`` file and afterwards rerunning + ``setup.py develop``:: + + setup( + #... + install_requires=[ + 'pyramid_chameleon', # new dependency + 'pyramid', + #... + ], + ) + + * Within the portion of your application which instantiates a Pyramid + ``~pyramid.config.Configurator`` (often the ``main()`` function in + your project's ``__init__.py`` file), tell Pyramid to include the + ``pyramid_chameleon`` includeme:: + + config = Configurator(.....) + config.include('pyramid_chameleon') + + Note that it's also fine to install these packages into *older* Pyramids for + forward compatibility purposes. Even if you don't upgrade to Pyramid 1.5 + immediately, performing the above steps in a Pyramid 1.4 installation is + perfectly fine, won't cause any difference, and will give you forward + compatibility when you eventually do upgrade to Pyramid 1.5. + + With the removal of Mako and Chameleon support from the core, some + unit tests that use the ``pyramid.renderers.render*`` methods may begin to + fail. If any of your unit tests are invoking either + ``pyramid.renderers.render()`` or ``pyramid.renderers.render_to_response()`` + with either Mako or Chameleon templates then the + ``pyramid.config.Configurator`` instance in effect during + the unit test should be also be updated to include the addons, as shown + above. For example:: + + class ATest(unittest.TestCase): + def setUp(self): + self.config = pyramid.testing.setUp() + self.config.include('pyramid_mako') + + def test_it(self): + result = pyramid.renderers.render('mypkg:templates/home.mako', {}) + + Or:: + + class ATest(unittest.TestCase): + def setUp(self): + self.config = pyramid.testing.setUp() + self.config.include('pyramid_chameleon') + + def test_it(self): + result = pyramid.renderers.render('mypkg:templates/home.pt', {}) + +- If you're using the Pyramid debug toolbar, when you upgrade Pyramid to + 1.5a2+, you'll also need to upgrade the ``pyramid_debugtoolbar`` package to + at least version 1.0.8, as older toolbar versions are not compatible with + Pyramid 1.5a2+ due to the removal of Mako support from the core. It's + fine to use this newer version of the toolbar code with older Pyramids too. + +- Removed the ``request.response_*`` varying attributes. These attributes + have been deprecated since Pyramid 1.1, and as per the deprecation policy, + have now been removed. + +- ``request.response`` will no longer be mutated when using the + ``pyramid.renderers.render()`` API. Almost all renderers mutate the + ``request.response`` response object (for example, the JSON renderer sets + ``request.response.content_type`` to ``application/json``), but this is + only necessary when the renderer is generating a response; it was a bug + when it was done as a side effect of calling ``pyramid.renderers.render()``. + +- Removed the ``bfg2pyramid`` fixer script. + +- The ``pyramid.events.NewResponse`` event is now sent **after** response + callbacks are executed. It previously executed before response callbacks + were executed. Rationale: it's more useful to be able to inspect the response + after response callbacks have done their jobs instead of before. + +- Removed the class named ``pyramid.view.static`` that had been deprecated + since Pyramid 1.1. Instead use ``pyramid.static.static_view`` with + ``use_subpath=True`` argument. + +- Removed the ``pyramid.view.is_response`` function that had been deprecated + since Pyramid 1.1. Use the ``pyramid.request.Request.is_response`` method + instead. + +- Removed the ability to pass the following arguments to + ``pyramid.config.Configurator.add_route``: ``view``, ``view_context``. + ``view_for``, ``view_permission``, ``view_renderer``, and ``view_attr``. + Using these arguments had been deprecated since Pyramid 1.1. Instead of + passing view-related arguments to ``add_route``, use a separate call to + ``pyramid.config.Configurator.add_view`` to associate a view with a route + using its ``route_name`` argument. Note that this impacts the + ``pyramid.config.Configurator.add_static_view`` function too, because it + delegates to ``add_route``. + +- Removed the ability to influence and query a ``pyramid.request.Request`` + object as if it were a dictionary. Previously it was possible to use methods + like ``__getitem__``, ``get``, ``items``, and other dictlike methods to + access values in the WSGI environment. This behavior had been deprecated + since Pyramid 1.1. Use methods of ``request.environ`` (a real dictionary) + instead. + +- Removed ancient backwards compatibily hack in + ``pyramid.traversal.DefaultRootFactory`` which populated the ``__dict__`` of + the factory with the matchdict values for compatibility with BFG 0.9. + +- The ``renderer_globals_factory`` argument to the + ``pyramid.config.Configurator` constructor and its ``setup_registry`` method + has been removed. The ``set_renderer_globals_factory`` method of + ``pyramid.config.Configurator`` has also been removed. The (internal) + ``pyramid.interfaces.IRendererGlobals`` interface was also removed. These + arguments, methods and interfaces had been deprecated since 1.1. Use a + ``BeforeRender`` event subscriber as documented in the "Hooks" chapter of the + Pyramid narrative documentation instead of providing renderer globals values + to the configurator. + +Deprecations +------------ + +- The ``pyramid.config.Configurator.set_request_property`` method now issues + a deprecation warning when used. It had been docs-deprecated in 1.4 + but did not issue a deprecation warning when used. + +1.5a1 (2013-08-30) +================== + +Features +-------- + +- A new http exception subclass named ``pyramid.httpexceptions.HTTPSuccessful`` + was added. You can use this class as the ``context`` of an exception + view to catch all 200-series "exceptions" (e.g. "raise HTTPOk"). This + also allows you to catch *only* the ``HTTPOk`` exception itself; previously + this was impossible because a number of other exceptions + (such as ``HTTPNoContent``) inherited from ``HTTPOk``, but now they do not. + +- You can now generate "hybrid" urldispatch/traversal URLs more easily + by using the new ``route_name``, ``route_kw`` and ``route_remainder_name`` + arguments to ``request.resource_url`` and ``request.resource_path``. See + the new section of the "Combining Traversal and URL Dispatch" documentation + chapter entitled "Hybrid URL Generation". + +- It is now possible to escape double braces in Pyramid scaffolds (unescaped, + these represent replacement values). You can use ``\{\{a\}\}`` to + represent a "bare" ``{{a}}``. See + https://github.com/Pylons/pyramid/pull/862 + +- Add ``localizer`` and ``locale_name`` properties (reified) to the request. + See https://github.com/Pylons/pyramid/issues/508. Note that the + ``pyramid.i18n.get_localizer`` and ``pyramid.i18n.get_locale_name`` functions + now simply look up these properties on the request. + +- 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. + +- Add the ability to invert the result of any view, route, or subscriber + predicate using the ``not_`` class. For example:: + + from pyramid.config import not_ + + @view_config(route_name='myroute', request_method=not_('POST')) + def myview(request): ... + + The above example will ensure that the view is called if the request method + is not POST (at least if no other view is more specific). + + The ``pyramid.config.not_`` class can be used against any value that is + a predicate value passed in any of these contexts: + + - ``pyramid.config.Configurator.add_view`` + + - ``pyramid.config.Configurator.add_route`` + + - ``pyramid.config.Configurator.add_subscriber`` + + - ``pyramid.view.view_config`` + + - ``pyramid.events.subscriber`` + +- ``scripts/prequest.py``: add support for submitting ``PUT`` and ``PATCH`` + requests. See https://github.com/Pylons/pyramid/pull/1033. add support for + submitting ``OPTIONS`` and ``PROPFIND`` requests, and allow users to specify + basic authentication credentials in the request via a ``--login`` argument to + the script. See https://github.com/Pylons/pyramid/pull/1039. + +- ``ACLAuthorizationPolicy`` supports ``__acl__`` as a callable. This + removes the ambiguity between the potential ``AttributeError`` that would + be raised on the ``context`` when the property was not defined and the + ``AttributeError`` that could be raised from any user-defined code within + a dynamic property. It is recommended to define a dynamic ACL as a callable + to avoid this ambiguity. See https://github.com/Pylons/pyramid/issues/735. + +- Allow a protocol-relative URL (e.g. ``//example.com/images``) to be passed to + ``pyramid.config.Configurator.add_static_view``. This allows + externally-hosted static URLs to be generated based on the current protocol. + +- The ``AuthTktAuthenticationPolicy`` has two new options to configure its + domain usage: + + * ``parent_domain``: if set the authentication cookie is set on + the parent domain. This is useful if you have multiple sites sharing the + same domain. + * ``domain``: if provided the cookie is always set for this domain, bypassing + all usual logic. + + See https://github.com/Pylons/pyramid/pull/1028, + https://github.com/Pylons/pyramid/pull/1072 and + https://github.com/Pylons/pyramid/pull/1078. + +- The ``AuthTktAuthenticationPolicy`` now supports IPv6 addresses when using + the ``include_ip=True`` option. This is possibly incompatible with + alternative ``auth_tkt`` implementations, as the specification does not + define how to properly handle IPv6. See + https://github.com/Pylons/pyramid/issues/831. + +- Make it possible to use variable arguments via + ``pyramid.paster.get_appsettings``. This also allowed the generated + ``initialize_db`` script from the ``alchemy`` scaffold to grow support + for options in the form ``a=1 b=2`` so you can fill in + values in a parameterized ``.ini`` file, e.g. + ``initialize_myapp_db etc/development.ini a=1 b=2``. + See https://github.com/Pylons/pyramid/pull/911 + +- The ``request.session.check_csrf_token()`` method and the ``check_csrf`` view + predicate now take into account the value of the HTTP header named + ``X-CSRF-Token`` (as well as the ``csrf_token`` form parameter, which they + always did). The header is tried when the form parameter does not exist. + +- View lookup will now search for valid views based on the inheritance + hierarchy of the context. It tries to find views based on the most + specific context first, and upon predicate failure, will move up the + inheritance chain to test views found by the super-type of the context. + In the past, only the most specific type containing views would be checked + and if no matching view could be found then a PredicateMismatch would be + raised. Now predicate mismatches don't hide valid views registered on + super-types. Here's an example that now works:: + + class IResource(Interface): + + ... + + @view_config(context=IResource) + def get(context, request): + + ... + + @view_config(context=IResource, request_method='POST') + def post(context, request): + + ... + + @view_config(context=IResource, request_method='DELETE') + def delete(context, request): + + ... + + @implementer(IResource) + class MyResource: + + ... + + @view_config(context=MyResource, request_method='POST') + def override_post(context, request): + + ... + + Previously the override_post view registration would hide the get + and delete views in the context of MyResource -- leading to a + predicate mismatch error when trying to use GET or DELETE + methods. Now the views are found and no predicate mismatch is + raised. + See https://github.com/Pylons/pyramid/pull/786 and + https://github.com/Pylons/pyramid/pull/1004 and + https://github.com/Pylons/pyramid/pull/1046 + +- The ``pserve`` command now takes a ``-v`` (or ``--verbose``) flag and a + ``-q`` (or ``--quiet``) flag. Output from running ``pserve`` can be + controlled using these flags. ``-v`` can be specified multiple times to + increase verbosity. ``-q`` sets verbosity to ``0`` unconditionally. The + default verbosity level is ``1``. + +- The ``alchemy`` scaffold tests now provide better coverage. See + https://github.com/Pylons/pyramid/pull/1029 + +- The ``pyramid.config.Configurator.add_route`` method now supports being + called with an external URL as pattern. See + https://github.com/Pylons/pyramid/issues/611 and the documentation section + in the "URL Dispatch" chapter entitled "External Routes" for more information. + +Bug Fixes +--------- + +- It was not possible to use ``pyramid.httpexceptions.HTTPException`` as + the ``context`` of an exception view as very general catchall for + http-related exceptions when you wanted that exception view to override the + default exception view. See https://github.com/Pylons/pyramid/issues/985 + +- When the ``pyramid.reload_templates`` setting was true, and a Chameleon + template was reloaded, and the renderer specification named a macro + (e.g. ``foo#macroname.pt``), renderings of the template after the template + was reloaded due to a file change would produce the entire template body + instead of just a rendering of the macro. See + https://github.com/Pylons/pyramid/issues/1013. + +- Fix an obscure problem when combining a virtual root with a route with a + ``*traverse`` in its pattern. Now the traversal path generated in + such a configuration will be correct, instead of an element missing + a leading slash. + +- Fixed a Mako renderer bug returning a tuple with a previous defname value + in some circumstances. See https://github.com/Pylons/pyramid/issues/1037 + for more information. + +- Make the ``pyramid.config.assets.PackageOverrides`` object implement the API + for ``__loader__`` objects specified in PEP 302. Proxies to the + ``__loader__`` set by the importer, if present; otherwise, raises + ``NotImplementedError``. This makes Pyramid static view overrides work + properly under Python 3.3 (previously they would not). See + https://github.com/Pylons/pyramid/pull/1015 for more information. + +- ``mako_templating``: added defensive workaround for non-importability of + ``mako`` due to upstream ``markupsafe`` dropping Python 3.2 support. Mako + templating will no longer work under the combination of MarkupSafe 0.17 and + Python 3.2 (although the combination of MarkupSafe 0.17 and Python 3.3 or any + supported Python 2 version will work OK). + +- Spaces and dots may now be in mako renderer template paths. This was + broken when support for the new makodef syntax was added in 1.4a1. + See https://github.com/Pylons/pyramid/issues/950 + +- ``pyramid.debug_authorization=true`` will now correctly print out + ``Allowed`` for views registered with ``NO_PERMISSION_REQUIRED`` instead + of invoking the ``permits`` method of the authorization policy. + See https://github.com/Pylons/pyramid/issues/954 + +- Pyramid failed to install on some systems due to being packaged with + some test files containing higher order characters in their names. These + files have now been removed. See + https://github.com/Pylons/pyramid/issues/981 + +- ``pyramid.testing.DummyResource`` didn't define ``__bool__``, so code under + Python 3 would use ``__len__`` to find truthiness; this usually caused an + instance of DummyResource to be "falsy" instead of "truthy". See + https://github.com/Pylons/pyramid/pull/1032 + +- The ``alchemy`` scaffold would break when the database was MySQL during + tables creation. See https://github.com/Pylons/pyramid/pull/1049 + +- The ``current_route_url`` method now attaches the query string to the URL by + default. See + https://github.com/Pylons/pyramid/issues/1040 + +- Make ``pserve.cherrypy_server_runner`` Python 3 compatible. See + https://github.com/Pylons/pyramid/issues/718 + +Backwards Incompatibilities +--------------------------- + +- Modified the ``current_route_url`` method in pyramid.Request. The method + previously returned the URL without the query string by default, it now does + attach the query string unless it is overriden. + +- The ``route_url`` and ``route_path`` APIs no longer quote ``/`` + to ``%2F`` when a replacement value contains a ``/``. This was pointless, + as WSGI servers always unquote the slash anyway, and Pyramid never sees the + quoted value. + +- It is no longer possible to set a ``locale_name`` attribute of the request, + nor is it possible to set a ``localizer`` attribute of the request. These + are now "reified" properties that look up a locale name and localizer + respectively using the machinery described in the "Internationalization" + chapter of the documentation. + +- If you send an ``X-Vhm-Root`` header with a value that ends with a slash (or + any number of slashes), the trailing slash(es) will be removed before a URL + is generated when you use use ``request.resource_url`` or + ``request.resource_path``. Previously the virtual root path would not have + trailing slashes stripped, which would influence URL generation. + +- The ``pyramid.interfaces.IResourceURL`` interface has now grown two new + attributes: ``virtual_path_tuple`` and ``physical_path_tuple``. These should + be the tuple form of the resource's path (physical and virtual). + 1.4 (2012-12-18) ================ diff --git a/RELEASING.txt b/RELEASING.txt index 88c3ad73d..87ff62c53 100644 --- a/RELEASING.txt +++ b/RELEASING.txt @@ -13,7 +13,7 @@ Releasing Pyramid Make sure statement coverage is at 100% (the test run will fail if not). -- Run Windows tests for Python 2.6, 2.7, 3.2, and 3.3 if feasible. +- Run tests on Windows if feasible. - Make sure all scaffold tests pass (Py 2.6, 2.7, 3.2, 3.3, 3.4, pypy, and pypy3 on UNIX; this doesn't work on Windows): @@ -24,16 +24,15 @@ Releasing Pyramid communicate with contributors). - Copy relevant changes (delta bug fixes) from CHANGES.txt to - docs/whatsnew-X.X (if it's a major release). + docs/whatsnew-X.X (if it's a major release). Minor releases should + include a link under "Bug Fix Releases" to the minor feature + changes in CHANGES.txt . - update README.rst to use correct versions of badges and URLs according to each branch and context, i.e., RTD "latest" == GitHub/Travis "1.x-branch". -- Make sure docs render OK:: - - $ tox -e {py2,py3}-docs - - There should be no meaningful errors or warnings. +- Update whatsnew-X.X.rst in docs to point at change log entries for individual + releases if applicable. - Change setup.py version to the new version number. @@ -46,10 +45,17 @@ Releasing Pyramid - Create a release tag. -- Make sure your system Python has ``setuptools-git`` installed and release to - PyPI:: +- Make sure your Python has ``setuptools-git``, ``twine`` and ``wheel`` + installed and release to PyPI:: + + $ python setup.py sdist bdist_wheel + $ twine upload dist/pyramid-X.X-* + +- Edit Pylons/pylonshq/templates/home/home.mako for minor and major updates. + +- Edit Pylons/pylonshq/templates/home/inside.rst for major updates only. - $ python setup.py sdist register upload +- Edit Pylons/pylonsrtd/pylonsrtd/docs/pyramid.rst for all updates. - Edit `http://wiki.python.org/moin/WebFrameworks <http://wiki.python.org/moin/WebFrameworks>`_. diff --git a/docs/Makefile b/docs/Makefile index 12dc88bf8..546deb30a 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -5,11 +5,12 @@ SPHINXOPTS = -W SPHINXBUILD = sphinx-build PAPER = +BUILDDIR = _build # Internal variables. PAPEROPT_a4 = -D latex_paper_size=a4 PAPEROPT_letter = -D latex_paper_size=letter -ALLSPHINXOPTS = -d _build/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . .PHONY: help clean html web pickle htmlhelp latex changes linkcheck @@ -23,71 +24,69 @@ help: @echo " linkcheck to check all external links for integrity" clean: - -rm -rf _build/* + -rm -rf $(BUILDDIR)/* -html: themes - mkdir -p _build/html _build/doctrees - $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) _build/html +html: + mkdir -p $(BUILDDIR)/html $(BUILDDIR)/doctrees + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html @echo - @echo "Build finished. The HTML pages are in _build/html." + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." text: - mkdir -p _build/text _build/doctrees - $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) _build/text + mkdir -p $(BUILDDIR)/text $(BUILDDIR)/doctrees + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text @echo - @echo "Build finished. The HTML pages are in _build/text." + @echo "Build finished. The HTML pages are in $(BUILDDIR)/text." pickle: - mkdir -p _build/pickle _build/doctrees - $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) _build/pickle + mkdir -p $(BUILDDIR)/pickle $(BUILDDIR)/doctrees + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle @echo @echo "Build finished; now you can process the pickle files or run" - @echo " sphinx-web _build/pickle" + @echo " sphinx-web $(BUILDDIR)/pickle" @echo "to start the sphinx-web server." web: pickle -htmlhelp: themes - mkdir -p _build/htmlhelp _build/doctrees - $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) _build/htmlhelp +htmlhelp: + mkdir -p $(BUILDDIR)/htmlhelp $(BUILDDIR)/doctrees + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp @echo @echo "Build finished; now you can run HTML Help Workshop with the" \ - ".hhp project file in _build/htmlhelp." + ".hhp project file in $(BUILDDIR)/htmlhelp." latex: - mkdir -p _build/latex _build/doctrees - $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) _build/latex - cp _static/*.png _build/latex + mkdir -p $(BUILDDIR)/latex $(BUILDDIR)/doctrees + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + cp _static/*.png $(BUILDDIR)/latex ./convert_images.sh - cp _static/latex-warning.png _build/latex - cp _static/latex-note.png _build/latex + cp _static/latex-warning.png $(BUILDDIR)/latex + cp _static/latex-note.png $(BUILDDIR)/latex @echo - @echo "Build finished; the LaTeX files are in _build/latex." + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." @echo "Run \`make latexpdf' to build a PDF file from them." latexpdf: - $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) _build/latex + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo "Running LaTeX files through pdflatex..." - $(MAKE) -C _build/latex all-pdf - @echo "pdflatex finished; the PDF file is in _build/latex." + $(MAKE) -C $(BUILDDIR)/latex all-pdf + @echo "pdflatex finished; the PDF file is in $(BUILDDIR)/latex." changes: - mkdir -p _build/changes _build/doctrees - $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) _build/changes + mkdir -p $(BUILDDIR)/changes $(BUILDDIR)/doctrees + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes @echo - @echo "The overview file is in _build/changes." + @echo "The overview file is in $(BUILDDIR)/changes." linkcheck: - mkdir -p _build/linkcheck _build/doctrees - $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) _build/linkcheck + mkdir -p $(BUILDDIR)/linkcheck $(BUILDDIR)/doctrees + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck @echo @echo "Link check complete; look for any errors in the above output " \ - "or in _build/linkcheck/output.txt." + "or in $(BUILDDIR)/linkcheck/output.txt." epub: - $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) _build/epub + $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub @echo - @echo "Build finished. The epub file is in _build/epub." + @echo "Build finished. The epub file is in $(BUILDDIR)/epub." -themes: - cd ..; git submodule update --init --recursive; cd docs; diff --git a/docs/_themes b/docs/_themes deleted file mode 160000 -Subproject 382cba80fbd6a7424818d17ec63ca520e485f10 diff --git a/docs/conf.py b/docs/conf.py index fa4578275..11e42c5f3 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -20,6 +20,7 @@ import warnings warnings.simplefilter('ignore', DeprecationWarning) import pkg_resources +import pylons_sphinx_themes # skip raw nodes from sphinx.writers.text import TextTranslator @@ -136,27 +137,8 @@ if book: # Options for HTML output # ----------------------- -# Add and use Pylons theme -if 'sphinx-build' in ' '.join(sys.argv): # protect against dumb importers - from subprocess import call, Popen, PIPE - cwd = os.getcwd() - p = Popen('which git', shell=True, stdout=PIPE) - here = os.path.abspath(os.path.dirname(__file__)) - parent = os.path.abspath(os.path.dirname(here)) - _themes = os.path.join(here, '_themes') - git = p.stdout.read().strip() - try: - os.chdir(parent) - if not os.listdir(_themes): - call([git, 'submodule', '--init']) - else: - call([git, 'submodule', 'update']) - sys.path.append(_themes) - finally: - os.chdir(cwd) - -html_theme_path = ['_themes'] html_theme = 'pyramid' +html_theme_path = pylons_sphinx_themes.get_html_themes_path() html_theme_options = dict( github_url='https://github.com/Pylons/pyramid', in_progress='true', diff --git a/docs/index.rst b/docs/index.rst index fc7560e8f..0ee3557bf 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -153,6 +153,7 @@ Change History .. toctree:: :maxdepth: 1 + whatsnew-1.6 whatsnew-1.5 whatsnew-1.4 whatsnew-1.3 diff --git a/docs/tutorials/wiki2/authorization.rst b/docs/tutorials/wiki2/authorization.rst index 2e35574fd..90a89d63e 100644 --- a/docs/tutorials/wiki2/authorization.rst +++ b/docs/tutorials/wiki2/authorization.rst @@ -211,7 +211,7 @@ routes: ``view_page`` route definition: .. literalinclude:: src/authorization/tutorial/__init__.py - :lines: 32 + :lines: 33 :linenos: :language: python diff --git a/docs/whatsnew-1.6.rst b/docs/whatsnew-1.6.rst new file mode 100644 index 000000000..b99ebeec4 --- /dev/null +++ b/docs/whatsnew-1.6.rst @@ -0,0 +1,170 @@ +What's New In Pyramid 1.6 +========================= + +This article explains the new features in :app:`Pyramid` version 1.6 as +compared to its predecessor, :app:`Pyramid` 1.5. It also documents backwards +incompatibilities between the two versions and deprecations added to +:app:`Pyramid` 1.6, as well as software dependency changes and notable +documentation additions. + +Backwards Incompatibilities +--------------------------- + +- ``request.response`` will no longer be mutated when using the + :func:`~pyramid.renderers.render_to_response` API. It is now necessary + to pass in + a ``response=`` argument to :func:`~pyramid.renderers.render_to_response` if + you wish to supply the renderer with a custom response object for it to + use. If you do not pass one then a response object will be created using the + current response factory. Almost all renderers mutate the + ``request.response`` response object (for example, the JSON renderer sets + ``request.response.content_type`` to ``application/json``). However, when + invoking ``render_to_response`` it is not expected that the response object + being returned would be the same one used later in the request. The response + object returned from ``render_to_response`` is now explicitly different from + ``request.response``. This does not change the API of a renderer. See + https://github.com/Pylons/pyramid/pull/1563 + + +Feature Additions +----------------- + +- Cache busting for static assets has been added and is available via a new + argument to :meth:`pyramid.config.Configurator.add_static_view`: + ``cachebust``. Core APIs are shipped for both cache busting via query + strings and path segments and may be extended to fit into custom asset + pipelines. See https://github.com/Pylons/pyramid/pull/1380 and + https://github.com/Pylons/pyramid/pull/1583 + +- Assets can now be overidden by an absolute path on the filesystem when using + the :meth:`~pyramid.config.Configurator.override_asset` API. This makes it + possible to fully support serving up static content from a mutable directory + while still being able to use the :meth:`~pyramid.request.Request.static_url` + API and :meth:`~pyramid.config.Configurator.add_static_view`. Previously it + was not possible to use :meth:`~pyramid.config.Configurator.add_static_view` + with an absolute path **and** generate urls to the content. This change + replaces the call, ``config.add_static_view('/abs/path', 'static')``, with + ``config.add_static_view('myapp:static', 'static')`` and + ``config.override_asset(to_override='myapp:static/', + override_with='/abs/path/')``. The ``myapp:static`` asset spec is completely + made up and does not need to exist - it is used for generating urls via + ``request.static_url('myapp:static/foo.png')``. See + https://github.com/Pylons/pyramid/issues/1252 + +- Added :meth:`~pyramid.config.Configurator.set_response_factory` and the + ``response_factory`` keyword argument to the constructor of + :class:`~pyramid.config.Configurator` for defining a factory that will return + a custom ``Response`` class. See https://github.com/Pylons/pyramid/pull/1499 + +- Add :attr:`pyramid.config.Configurator.root_package` attribute and init + parameter to assist with includeable packages that wish to resolve + resources relative to the package in which the configurator was created. + This is especially useful for addons that need to load asset specs from + settings, in which case it is may be natural for a developer to define + imports or assets relative to the top-level package. + See https://github.com/Pylons/pyramid/pull/1337 + +- Overall improvments for the ``proutes`` command. Added ``--format`` and + ``--glob`` arguments to the command, introduced the ``method`` + column for displaying available request methods, and improved the ``view`` + output by showing the module instead of just ``__repr__``. + See https://github.com/Pylons/pyramid/pull/1488 + +- ``pserve`` can now take a ``-b`` or ``--browser`` option to open the server + URL in a web browser. See https://github.com/Pylons/pyramid/pull/1533 + +- Support keyword-only arguments and function annotations in views in + Python 3. See https://github.com/Pylons/pyramid/pull/1556 + +- The ``append_slash`` argument of + :meth:`~pyramid.config.Configurator.add_notfound_view()` will now accept + anything that implements the :class:`~pyramid.interfaces.IResponse` interface + and will use that as the response class instead of the default + :class:`~pyramid.httpexceptions.HTTPFound`. See + https://github.com/Pylons/pyramid/pull/1610 + +- The :class:`~pyramid.config.Configurator` has grown the ability to allow + actions to call other actions during a commit-cycle. This enables much more + logic to be placed into actions, such as the ability to invoke other actions + or group them for improved conflict detection. We have also exposed and + documented the config phases that Pyramid uses in order to further assist in + building conforming addons. See https://github.com/Pylons/pyramid/pull/1513 + +- Allow an iterator to be returned from a renderer. Previously it was only + possible to return bytes or unicode. + See https://github.com/Pylons/pyramid/pull/1417 + +- Improve robustness to timing attacks in the + :class:`~pyramid.authentication.AuthTktCookieHelper` and the + :class:`~pyramid.session.SignedCookieSessionFactory` classes by using the + stdlib's ``hmac.compare_digest`` if it is available (such as Python 2.7.7+ and + 3.3+). See https://github.com/Pylons/pyramid/pull/1457 + +- Improve the readability of the ``pcreate`` shell script output. + See https://github.com/Pylons/pyramid/pull/1453 + +- Make it simple to define notfound and forbidden views that wish to use the + default exception-response view but with altered predicates and other + configuration options. The ``view`` argument is now optional in + :meth:`~pyramid.config.Configurator.add_notfound_view` and + :meth:`~pyramid.config.Configurator.add_forbidden_view` See + https://github.com/Pylons/pyramid/issues/494 + +- The ``pshell`` script will now load a ``PYTHONSTARTUP`` file if one is + defined in the environment prior to launching the interpreter. + See https://github.com/Pylons/pyramid/pull/1448 + +- Add new HTTP exception objects for status codes + ``428 Precondition Required``, ``429 Too Many Requests`` and + ``431 Request Header Fields Too Large`` in ``pyramid.httpexceptions``. + See https://github.com/Pylons/pyramid/pull/1372/files + +- ``pcreate`` when run without a scaffold argument will now print information + on the missing flag, as well as a list of available scaffolds. See + https://github.com/Pylons/pyramid/pull/1566 and + https://github.com/Pylons/pyramid/issues/1297 + +- Add :func:`pyramid.request.apply_request_extensions` function which can be + used in testing to apply any request extensions configured via + ``config.add_request_method``. Previously it was only possible to test the + extensions by going through Pyramid's router. See + https://github.com/Pylons/pyramid/pull/1581 + + +- Make it possible to subclass ``pyramid.request.Request`` and also use + ``pyramid.request.Request.add_request.method``. See + https://github.com/Pylons/pyramid/issues/1529 + +Deprecations +------------ + +- The ``principal`` argument to :func:`pyramid.security.remember` was renamed + to ``userid``. Using ``principal`` as the argument name still works and will + continue to work for the next few releases, but a deprecation warning is + printed. + + +Scaffolding Enhancements +------------------------ + +- Added line numbers to the log formatters in the scaffolds to assist with + debugging. See https://github.com/Pylons/pyramid/pull/1326 + +- Update scaffold generating machinery to return the version of pyramid and + pyramid docs for use in scaffolds. Updated ``starter``, ``alchemy`` and + ``zodb`` templates to have links to correctly versioned documentation and + reflect which pyramid was used to generate the scaffold. + +- Removed non-ascii copyright symbol from templates, as this was + causing the scaffolds to fail for project generation. + +Documentation Enhancements +-------------------------- + +- Removed logging configuration from Quick Tutorial ini files except for + scaffolding- and logging-related chapters to avoid needing to explain it too + early. + +- Improve and clarify the documentation on what Pyramid defines as a + ``principal`` and a ``userid`` in its security APIs. + See https://github.com/Pylons/pyramid/pull/1399 diff --git a/pyramid/authentication.py b/pyramid/authentication.py index e0e241e52..0924b5901 100644 --- a/pyramid/authentication.py +++ b/pyramid/authentication.py @@ -36,6 +36,7 @@ from pyramid.util import strings_differ VALID_TOKEN = re.compile(r"^[A-Za-z][A-Za-z0-9+_-]*$") + class CallbackAuthenticationPolicy(object): """ Abstract class """ @@ -77,10 +78,10 @@ class CallbackAuthenticationPolicy(object): debug and self._log( ('use of userid %r is disallowed by any built-in Pyramid ' 'security policy, returning None' % userid), - 'authenticated_userid' , + 'authenticated_userid', request) return None - + if self.callback is None: debug and self._log( 'there was no groupfinder callback; returning %r' % (userid,), @@ -146,7 +147,7 @@ class CallbackAuthenticationPolicy(object): request ) return effective_principals - + if self.callback is None: debug and self._log( 'groupfinder callback is None, so groups is []', @@ -178,9 +179,10 @@ class CallbackAuthenticationPolicy(object): effective_principals,), 'effective_principals', request - ) + ) return effective_principals + @implementer(IAuthenticationPolicy) class RepozeWho1AuthenticationPolicy(CallbackAuthenticationPolicy): """ A :app:`Pyramid` :term:`authentication policy` which @@ -248,7 +250,7 @@ class RepozeWho1AuthenticationPolicy(CallbackAuthenticationPolicy): 'authenticated_userid', request) return None - + if self._clean_principal(userid) is None: self.debug and self._log( ('use of userid %r is disallowed by any built-in Pyramid ' @@ -336,7 +338,7 @@ class RepozeWho1AuthenticationPolicy(CallbackAuthenticationPolicy): def remember(self, request, userid, **kw): """ Store the ``userid`` as ``repoze.who.userid``. - + The identity to authenticated to :mod:`repoze.who` will contain the given userid as ``userid``, and provide all keyword arguments as additional identity @@ -839,15 +841,15 @@ class AuthTktCookieHelper(object): hashalg='md5', parent_domain=False, domain=None): serializer = _SimpleSerializer() - + self.cookie_profile = CookieProfile( - cookie_name = cookie_name, - secure = secure, - max_age = max_age, - httponly = http_only, - path = path, + cookie_name=cookie_name, + secure=secure, + max_age=max_age, + httponly=http_only, + path=path, serializer=serializer - ) + ) self.secret = secret self.cookie_name = cookie_name @@ -882,7 +884,7 @@ class AuthTktCookieHelper(object): kw['domains'] = domains if max_age is not None: kw['max_age'] = max_age - + headers = profile.get_headers(value, **kw) return headers @@ -1187,4 +1189,3 @@ class _SimpleSerializer(object): def dumps(self, appstruct): return bytes_(appstruct) - diff --git a/pyramid/authorization.py b/pyramid/authorization.py index 5e7baa19d..4845762ef 100644 --- a/pyramid/authorization.py +++ b/pyramid/authorization.py @@ -73,7 +73,7 @@ class ACLAuthorizationPolicy(object): :class:`pyramid.security.ACLDenied` if not.""" acl = '<No ACL found on any object in resource lineage>' - + for location in lineage(context): try: acl = location.__acl__ @@ -121,7 +121,7 @@ class ACLAuthorizationPolicy(object): allowed_here = set() denied_here = set() - + if acl and callable(acl): acl = acl() @@ -129,7 +129,7 @@ class ACLAuthorizationPolicy(object): if not is_nonstr_iter(ace_permissions): ace_permissions = [ace_permissions] if (ace_action == Allow) and (permission in ace_permissions): - if not ace_principal in denied_here: + if ace_principal not in denied_here: allowed_here.add(ace_principal) if (ace_action == Deny) and (permission in ace_permissions): denied_here.add(ace_principal) diff --git a/pyramid/config/__init__.py b/pyramid/config/__init__.py index 549144fab..5a1b7b122 100644 --- a/pyramid/config/__init__.py +++ b/pyramid/config/__init__.py @@ -436,7 +436,7 @@ class Configurator( if session_factory is not None: self.set_session_factory(session_factory) - tweens = aslist(registry.settings.get('pyramid.tweens', [])) + tweens = aslist(registry.settings.get('pyramid.tweens', [])) for factory in tweens: self._add_tween(factory, explicit=True) @@ -965,11 +965,11 @@ class Configurator( if package is None: # pragma: no cover package = caller_package() - ctorkw = {'config':self} + ctorkw = {'config': self} ctorkw.update(kw) scanner = self.venusian.Scanner(**ctorkw) - + scanner.scan(package, categories=categories, onerror=onerror, ignore=ignore) @@ -990,7 +990,7 @@ class Configurator( # Push the registry onto the stack in case any code that depends on # the registry threadlocal APIs used in listeners subscribed to the # IApplicationCreated event. - self.manager.push({'registry':self.registry, 'request':None}) + self.manager.push({'registry': self.registry, 'request': None}) try: self.registry.notify(ApplicationCreated(app)) finally: @@ -998,6 +998,7 @@ class Configurator( return app + # this class is licensed under the ZPL (stolen from Zope) class ActionState(object): def __init__(self): @@ -1151,9 +1152,9 @@ class ActionState(object): # O(n lg n). all_actions.extend(self.actions) pending_actions = resume(resolveConflicts( - executed_actions - + list(pending_actions) - + self.actions + executed_actions + + list(pending_actions) + + self.actions )) self.actions = [] @@ -1287,18 +1288,20 @@ def resolveConflicts(actions): for _, _, action in rest: includepath = action['includepath'] # Test whether path is a prefix of opath - if (includepath[:len(basepath)] != basepath # not a prefix - or includepath == basepath): + if (includepath[:len(basepath)] != basepath or # not a prefix + includepath == basepath): L = conflicts.setdefault(discriminator, [baseinfo]) L.append(action['info']) if conflicts: raise ConfigurationConflictError(conflicts) - # sort conflict-resolved actions by (order, i) and yield them one by one + # sort conflict-resolved actions by (order, i) and yield them one + # by one for a in [x[2] for x in sorted(output, key=operator.itemgetter(0, 1))]: yield a - + + def expand_action(discriminator, callable=None, args=(), kw=None, includepath=(), info=None, order=0, introspectables=()): if kw is None: diff --git a/pyramid/config/adapters.py b/pyramid/config/adapters.py index 3d11980da..a68070134 100644 --- a/pyramid/config/adapters.py +++ b/pyramid/config/adapters.py @@ -255,7 +255,7 @@ class AdaptersConfiguratorMixin(object): See :ref:`changing_the_traverser` for more information. """ iface = self.maybe_dotted(iface) - adapter= self.maybe_dotted(adapter) + adapter = self.maybe_dotted(adapter) def register(iface=iface): if iface is None: iface = Interface diff --git a/pyramid/config/assets.py b/pyramid/config/assets.py index 6dabea358..bbdf18ced 100644 --- a/pyramid/config/assets.py +++ b/pyramid/config/assets.py @@ -20,7 +20,7 @@ class OverrideProvider(pkg_resources.DefaultProvider): reg = get_current_registry() overrides = reg.queryUtility(IPackageOverrides, self.module_name) return overrides - + def get_resource_filename(self, manager, resource_name): """ Return a true filesystem path for resource_name, co-ordinating the extraction with manager, if the resource @@ -33,12 +33,12 @@ class OverrideProvider(pkg_resources.DefaultProvider): return filename return pkg_resources.DefaultProvider.get_resource_filename( self, manager, resource_name) - + def get_resource_stream(self, manager, resource_name): """ Return a readable file-like object for resource_name.""" overrides = self._get_overrides() if overrides is not None: - stream = overrides.get_stream(resource_name) + stream = overrides.get_stream(resource_name) if stream is not None: return stream return pkg_resources.DefaultProvider.get_resource_stream( @@ -387,5 +387,3 @@ class AssetsConfiguratorMixin(object): self.action(None, register, introspectables=(intr,)) override_resource = override_asset # bw compat - - diff --git a/pyramid/config/util.py b/pyramid/config/util.py index 23cdc6be8..0fd9ef4a7 100644 --- a/pyramid/config/util.py +++ b/pyramid/config/util.py @@ -151,7 +151,7 @@ class PredicateList(object): hashes = [hashes] for h in hashes: phash.update(bytes_(h)) - weights.append(1 << n+1) + weights.append(1 << n + 1) preds.append(pred) if kw: raise ConfigurationError('Unknown predicate values: %r' % (kw,)) diff --git a/pyramid/config/views.py b/pyramid/config/views.py index e2da950be..a522880c4 100644 --- a/pyramid/config/views.py +++ b/pyramid/config/views.py @@ -157,7 +157,7 @@ class ViewDeriver(object): self.decorated_view( self.rendered_view( self.mapped_view( - view))))))))) + view))))))))) @wraps_view def mapped_view(self, view): @@ -232,7 +232,11 @@ class ViewDeriver(object): permission = None wrapped_view = view - if self.authn_policy and self.authz_policy and (permission is not None): + if ( + self.authn_policy and + self.authz_policy and + (permission is not None) + ): def _permitted(context, request): principals = self.authn_policy.effective_principals(request) return self.authz_policy.permits(context, principals, @@ -270,7 +274,8 @@ class ViewDeriver(object): else: principals = self.authn_policy.effective_principals( request) - msg = str(self.authz_policy.permits(context, principals, + msg = str(self.authz_policy.permits(context, + principals, permission)) else: msg = 'Allowed (no authorization policy in use)' @@ -293,14 +298,16 @@ class ViewDeriver(object): preds = self.kw.get('predicates', ()) if not preds: return view + def predicate_wrapper(context, request): for predicate in preds: if not predicate(context, request): view_name = getattr(view, '__name__', view) raise PredicateMismatch( - 'predicate mismatch for view %s (%s)' % ( - view_name, predicate.text())) + 'predicate mismatch for view %s (%s)' % ( + view_name, predicate.text())) return view(context, request) + def checker(context, request): return all((predicate(context, request) for predicate in preds)) @@ -321,7 +328,7 @@ class ViewDeriver(object): (accept is None) and (order == MAX_ORDER) and (phash == DEFAULT_PHASH) - ): + ): return view # defaults def attr_view(context, request): return view(context, request) @@ -350,7 +357,7 @@ class ViewDeriver(object): def _rendered_view(self, view, view_renderer): def rendered_view(context, request): result = view(context, request) - if result.__class__ is Response: # potential common case + if result.__class__ is Response: # potential common case response = result else: registry = self.registry @@ -365,9 +372,10 @@ class ViewDeriver(object): renderer = renderers.RendererHelper( name=renderer_name, package=self.kw.get('package'), - registry = registry) + registry=registry) else: renderer = view_renderer.clone() + if '__view__' in attrs: view_inst = attrs.pop('__view__') else: @@ -380,9 +388,10 @@ class ViewDeriver(object): def _response_resolved_view(self, view): registry = self.registry + def viewresult_to_response(context, request): result = view(context, request) - if result.__class__ is Response: # common case + if result.__class__ is Response: # common case response = result else: response = registry.queryAdapterOrSelf(result, IResponse) @@ -413,6 +422,7 @@ class ViewDeriver(object): return view return decorator(view) + @implementer(IViewMapper) @provider(IViewMapperFactory) class DefaultViewMapper(object): @@ -631,7 +641,8 @@ class ViewsConfiguratorMixin(object): http_cache=None, match_param=None, check_csrf=None, - **predicates): + **predicates + ): """ Add a :term:`view configuration` to the current configuration state. Arguments to ``add_view`` are broken down below into *predicate* arguments and *non-predicate* @@ -1126,7 +1137,7 @@ class ViewsConfiguratorMixin(object): if isinstance(renderer, string_types): renderer = renderers.RendererHelper( name=renderer, package=self.package, - registry = self.registry) + registry=self.registry) if accept is not None: accept = accept.lower() @@ -1154,7 +1165,11 @@ class ViewsConfiguratorMixin(object): # is. It can't be computed any sooner because thirdparty # predicates may not yet exist when add_view is called. order, preds, phash = predlist.make(self, **pvals) - view_intr.update({'phash':phash, 'order':order, 'predicates':preds}) + view_intr.update({ + 'phash': phash, + 'order': order, + 'predicates': preds + }) return ('view', context, name, route_name, phash) discriminator = Deferred(discrim_func) @@ -1353,7 +1368,7 @@ class ViewsConfiguratorMixin(object): tmpl_intr is not None and intrspc is not None and intrspc.get('renderer factories', renderer_type) is not None - ): + ): # allow failure of registered template factories to be deferred # until view execution, like other bad renderer factories; if # we tried to relate this to an existing renderer factory @@ -1395,7 +1410,7 @@ class ViewsConfiguratorMixin(object): permission, permission, 'permission' - ) + ) perm_intr['value'] = permission perm_intr.relate('views', discriminator) introspectables.append(perm_intr) @@ -1427,7 +1442,7 @@ class ViewsConfiguratorMixin(object): factory, weighs_more_than=weighs_more_than, weighs_less_than=weighs_less_than - ) + ) def add_default_view_predicates(self): p = pyramid.config.predicates @@ -1445,7 +1460,7 @@ class ViewsConfiguratorMixin(object): ('physical_path', p.PhysicalPathPredicate), ('effective_principals', p.EffectivePrincipalsPredicate), ('custom', p.CustomPredicate), - ): + ): self.add_view_predicate(name, factory) def derive_view(self, view, attr=None, renderer=None): @@ -1537,7 +1552,7 @@ class ViewsConfiguratorMixin(object): if isinstance(renderer, string_types): renderer = renderers.RendererHelper( name=renderer, package=self.package, - registry = self.registry) + registry=self.registry) if renderer is None: # use default renderer if one exists if self.registry.queryUtility(IRendererFactory) is not None: @@ -1585,7 +1600,7 @@ class ViewsConfiguratorMixin(object): mapper=None, match_param=None, **predicates - ): + ): """ Add a forbidden view to the current configuration state. The view will be called when Pyramid or application code raises a :exc:`pyramid.httpexceptions.HTTPForbidden` exception and the set of @@ -1618,7 +1633,7 @@ class ViewsConfiguratorMixin(object): raise ConfigurationError( '%s may not be used as an argument to add_forbidden_view' % arg - ) + ) if view is None: view = default_exceptionresponse_view @@ -1643,7 +1658,7 @@ class ViewsConfiguratorMixin(object): permission=NO_PERMISSION_REQUIRED, attr=attr, renderer=renderer, - ) + ) settings.update(predicates) return self.add_view(**settings) @@ -1672,7 +1687,7 @@ class ViewsConfiguratorMixin(object): match_param=None, append_slash=False, **predicates - ): + ): """ Add a default Not Found View to the current configuration state. The view will be called when Pyramid or application code raises an :exc:`pyramid.httpexceptions.HTTPNotFound` exception (e.g. when a @@ -1730,7 +1745,7 @@ class ViewsConfiguratorMixin(object): raise ConfigurationError( '%s may not be used as an argument to add_notfound_view' % arg - ) + ) if view is None: view = default_exceptionresponse_view @@ -1753,7 +1768,7 @@ class ViewsConfiguratorMixin(object): match_param=match_param, route_name=route_name, permission=NO_PERMISSION_REQUIRED, - ) + ) settings.update(predicates) if append_slash: view = self._derive_view(view, attr=attr, renderer=renderer) @@ -1931,7 +1946,7 @@ def isexception(o): return ( isinstance(o, Exception) or (inspect.isclass(o) and (issubclass(o, Exception))) - ) + ) @implementer(IStaticURLInfo) @@ -2045,7 +2060,7 @@ class StaticURLInfo(object): # register a route using the computed view, permission, and # pattern, plus any extras passed to us via add_static_view - pattern = "%s*subpath" % name # name already ends with slash + pattern = "%s*subpath" % name # name already ends with slash if config.route_prefix: route_name = '__%s/%s' % (config.route_prefix, name) else: @@ -2057,12 +2072,12 @@ class StaticURLInfo(object): permission=permission, context=context, renderer=renderer, - ) + ) def register(): registrations = self._get_registrations(config.registry) - names = [ t[0] for t in registrations ] + names = [t[0] for t in registrations] if name in names: idx = names.index(name) @@ -2079,4 +2094,3 @@ class StaticURLInfo(object): intr['spec'] = spec config.action(None, callable=register, introspectables=(intr,)) - diff --git a/pyramid/exceptions.py b/pyramid/exceptions.py index c59d109df..c1481ce9c 100644 --- a/pyramid/exceptions.py +++ b/pyramid/exceptions.py @@ -33,7 +33,7 @@ class PredicateMismatch(HTTPNotFound): be treated as :class:`HTTPNotFound`` by any exception view registrations. Thus, typically, this exception will not be seen publicly. - + However, this exception will be raised if the predicates of all views configured to handle another exception context cannot be successfully matched. For instance, if a view is configured to @@ -79,7 +79,7 @@ class ConfigurationConflictError(ConfigurationError): r.append(" For: %s" % (discriminator, )) for info in infos: for line in str(info).rstrip().split(CR): - r.append(" "+line) + r.append(" " + line) return CR.join(r) @@ -109,5 +109,3 @@ class CyclicDependencyError(Exception): L.append('%r sorts before %r' % (dependent, dependees)) msg = 'Implicit ordering cycle:' + '; '.join(L) return msg - - diff --git a/pyramid/httpexceptions.py b/pyramid/httpexceptions.py index a30129e16..465769834 100644 --- a/pyramid/httpexceptions.py +++ b/pyramid/httpexceptions.py @@ -116,10 +116,10 @@ Substitution of response headers into template values is always performed. Substitution of WSGI environment values is performed if a ``request`` is passed to the exception's constructor. -The subclasses of :class:`~_HTTPMove` +The subclasses of :class:`~_HTTPMove` (:class:`~HTTPMultipleChoices`, :class:`~HTTPMovedPermanently`, :class:`~HTTPFound`, :class:`~HTTPSeeOther`, :class:`~HTTPUseProxy` and -:class:`~HTTPTemporaryRedirect`) are redirections that require a ``Location`` +:class:`~HTTPTemporaryRedirect`) are redirections that require a ``Location`` field. Reflecting this, these subclasses have one additional keyword argument: ``location``, which indicates the location to which to redirect. """ @@ -296,7 +296,7 @@ class HTTPError(HTTPException): base class for exceptions with status codes in the 400s and 500s This is an exception which indicates that an error has occurred, - and that any work in progress should not be committed. + and that any work in progress should not be committed. """ class HTTPRedirection(HTTPException): @@ -324,7 +324,7 @@ class HTTPOk(HTTPSuccessful): subclass of :class:`~HTTPSuccessful` Indicates that the request has succeeded. - + code: 200, title: OK """ code = 200 @@ -336,7 +336,7 @@ class HTTPCreated(HTTPSuccessful): This indicates that request has been fulfilled and resulted in a new resource being created. - + code: 201, title: Created """ code = 201 @@ -375,7 +375,7 @@ class HTTPNoContent(HTTPSuccessful): This indicates that the server has fulfilled the request but does not need to return an entity-body, and might want to return updated metainformation. - + code: 204, title: No Content """ code = 204 @@ -389,7 +389,7 @@ class HTTPResetContent(HTTPSuccessful): This indicates that the server has fulfilled the request and the user agent SHOULD reset the document view which caused the request to be sent. - + code: 205, title: Reset Content """ code = 205 @@ -402,7 +402,7 @@ class HTTPPartialContent(HTTPSuccessful): This indicates that the server has fulfilled the partial GET request for the resource. - + code: 206, title: Partial Content """ code = 206 @@ -460,7 +460,7 @@ class HTTPMultipleChoices(_HTTPMove): and agent-driven negotiation information is being provided so that the user can select a preferred representation and redirect its request to that location. - + code: 300, title: Multiple Choices """ code = 300 @@ -485,7 +485,7 @@ class HTTPFound(_HTTPMove): This indicates that the requested resource resides temporarily under a different URI. - + code: 302, title: Found """ code = 302 @@ -501,7 +501,7 @@ class HTTPSeeOther(_HTTPMove): This indicates that the response to the request can be found under a different URI and SHOULD be retrieved using a GET method on that resource. - + code: 303, title: See Other """ code = 303 @@ -528,7 +528,7 @@ class HTTPUseProxy(_HTTPMove): This indicates that the requested resource MUST be accessed through the proxy given by the Location field. - + code: 305, title: Use Proxy """ # Not a move, but looks a little like one @@ -543,7 +543,7 @@ class HTTPTemporaryRedirect(_HTTPMove): This indicates that the requested resource resides temporarily under a different URI. - + code: 307, title: Temporary Redirect """ code = 307 @@ -583,7 +583,7 @@ class HTTPUnauthorized(HTTPClientError): subclass of :class:`~HTTPClientError` This indicates that the request requires user authentication. - + code: 401, title: Unauthorized """ code = 401 @@ -597,7 +597,7 @@ class HTTPUnauthorized(HTTPClientError): class HTTPPaymentRequired(HTTPClientError): """ subclass of :class:`~HTTPClientError` - + code: 402, title: Payment Required """ code = 402 @@ -636,7 +636,7 @@ class HTTPForbidden(HTTPClientError): # differences from webob.exc.HTTPForbidden: # # - accepts a ``result`` keyword argument - # + # # - overrides constructor to set ``self.result`` # # differences from older ``pyramid.exceptions.Forbidden``: @@ -659,7 +659,7 @@ class HTTPNotFound(HTTPClientError): This indicates that the server did not find anything matching the Request-URI. - + code: 404, title: Not Found Raise this exception within :term:`view` code to immediately @@ -702,7 +702,7 @@ class HTTPNotAcceptable(HTTPClientError): capable of generating response entities which have content characteristics not acceptable according to the accept headers sent in the request. - + code: 406, title: Not Acceptable """ # differences from webob.exc.HTTPNotAcceptable: @@ -717,7 +717,7 @@ class HTTPProxyAuthenticationRequired(HTTPClientError): This is similar to 401, but indicates that the client must first authenticate itself with the proxy. - + code: 407, title: Proxy Authentication Required """ code = 407 @@ -730,7 +730,7 @@ class HTTPRequestTimeout(HTTPClientError): This indicates that the client did not produce a request within the time that the server was prepared to wait. - + code: 408, title: Request Timeout """ code = 408 @@ -744,7 +744,7 @@ class HTTPConflict(HTTPClientError): This indicates that the request could not be completed due to a conflict with the current state of the resource. - + code: 409, title: Conflict """ code = 409 @@ -758,7 +758,7 @@ class HTTPGone(HTTPClientError): This indicates that the requested resource is no longer available at the server and no forwarding address is known. - + code: 410, title: Gone """ code = 410 @@ -772,7 +772,7 @@ class HTTPLengthRequired(HTTPClientError): This indicates that the server refuses to accept the request without a defined Content-Length. - + code: 411, title: Length Required """ code = 411 @@ -786,7 +786,7 @@ class HTTPPreconditionFailed(HTTPClientError): This indicates that the precondition given in one or more of the request-header fields evaluated to false when it was tested on the server. - + code: 412, title: Precondition Failed """ code = 412 @@ -814,7 +814,7 @@ class HTTPRequestURITooLong(HTTPClientError): This indicates that the server is refusing to service the request because the Request-URI is longer than the server is willing to interpret. - + code: 414, title: Request-URI Too Long """ code = 414 @@ -828,7 +828,7 @@ class HTTPUnsupportedMediaType(HTTPClientError): This indicates that the server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method. - + code: 415, title: Unsupported Media Type """ # differences from webob.exc.HTTPUnsupportedMediaType: @@ -846,7 +846,7 @@ class HTTPRequestRangeNotSatisfiable(HTTPClientError): range-specifier values in this field overlap the current extent of the selected resource, and the request did not include an If-Range request-header field. - + code: 416, title: Request Range Not Satisfiable """ code = 416 @@ -859,7 +859,7 @@ class HTTPExpectationFailed(HTTPClientError): This indidcates that the expectation given in an Expect request-header field could not be met by this server. - + code: 417, title: Expectation Failed """ code = 417 @@ -871,13 +871,13 @@ class HTTPUnprocessableEntity(HTTPClientError): subclass of :class:`~HTTPClientError` This indicates that the server is unable to process the contained - instructions. + instructions. May be used to notify the client that their JSON/XML is well formed, but not correct for the current request. See RFC4918 section 11 for more information. - + code: 422, title: Unprocessable Entity """ ## Note: from WebDAV @@ -890,7 +890,7 @@ class HTTPLocked(HTTPClientError): subclass of :class:`~HTTPClientError` This indicates that the resource is locked. - + code: 423, title: Locked """ ## Note: from WebDAV @@ -904,7 +904,7 @@ class HTTPFailedDependency(HTTPClientError): This indicates that the method could not be performed because the requested action depended on another action and that action failed. - + code: 424, title: Failed Dependency """ ## Note: from WebDAV @@ -1003,7 +1003,7 @@ class HTTPNotImplemented(HTTPServerError): This indicates that the server does not support the functionality required to fulfill the request. - + code: 501, title: Not Implemented """ # differences from webob.exc.HTTPNotAcceptable: @@ -1019,7 +1019,7 @@ class HTTPBadGateway(HTTPServerError): This indicates that the server, while acting as a gateway or proxy, received an invalid response from the upstream server it accessed in attempting to fulfill the request. - + code: 502, title: Bad Gateway """ code = 502 @@ -1032,7 +1032,7 @@ class HTTPServiceUnavailable(HTTPServerError): This indicates that the server is currently unable to handle the request due to a temporary overloading or maintenance of the server. - + code: 503, title: Service Unavailable """ code = 503 @@ -1075,7 +1075,7 @@ class HTTPInsufficientStorage(HTTPServerError): This indicates that the server does not have enough space to save the resource. - + code: 507, title: Insufficient Storage """ code = 507 @@ -1100,12 +1100,14 @@ def default_exceptionresponse_view(context, request): context = request.exception or context return context # assumed to be an IResponse -status_map={} +status_map = {} code = None for name, value in list(globals().items()): - if (isinstance(value, class_types) and - issubclass(value, HTTPException) - and not name.startswith('_')): + if ( + isinstance(value, class_types) and + issubclass(value, HTTPException) and + not name.startswith('_') + ): code = getattr(value, 'code', None) if code: status_map[code] = value diff --git a/pyramid/i18n.py b/pyramid/i18n.py index c30351f7a..458f6168d 100644 --- a/pyramid/i18n.py +++ b/pyramid/i18n.py @@ -8,9 +8,6 @@ from translationstring import ( TranslationStringFactory, # API ) -TranslationString = TranslationString # PyFlakes -TranslationStringFactory = TranslationStringFactory # PyFlakes - from pyramid.compat import PY3 from pyramid.decorator import reify @@ -22,6 +19,10 @@ from pyramid.interfaces import ( from pyramid.threadlocal import get_current_registry +TranslationString = TranslationString # PyFlakes +TranslationStringFactory = TranslationStringFactory # PyFlakes + + class Localizer(object): """ An object providing translation and pluralizations related to diff --git a/pyramid/interfaces.py b/pyramid/interfaces.py index bab91b0ee..7b9a850d1 100644 --- a/pyramid/interfaces.py +++ b/pyramid/interfaces.py @@ -149,7 +149,7 @@ class IResponse(Interface): """Gets and sets and deletes the Content-MD5 header. For more information on Content-MD5 see RFC 2616 section 14.14.""") - content_range = Attribute( + content_range = Attribute( """Gets and sets and deletes the Content-Range header. For more information on Content-Range see section 14.16. Converts using ContentRange object.""") diff --git a/pyramid/path.py b/pyramid/path.py index f2d8fff55..b79c5a6ac 100644 --- a/pyramid/path.py +++ b/pyramid/path.py @@ -15,7 +15,7 @@ init_names = [ '__init__%s' % x[0] for x in imp.get_suffixes() if def caller_path(path, level=2): if not os.path.isabs(path): - module = caller_module(level+1) + module = caller_module(level + 1) prefix = package_path(module) path = os.path.join(prefix, path) return path @@ -53,7 +53,7 @@ def package_of(pkg_or_module): def caller_package(level=2, caller_module=caller_module): # caller_module in arglist for tests - module = caller_module(level+1) + module = caller_module(level + 1) f = getattr(module, '__file__', '') if (('__init__.py' in f) or ('__init__$py' in f)): # empty at >>> # Module is a package diff --git a/pyramid/registry.py b/pyramid/registry.py index fb4ec52e2..1073134ff 100644 --- a/pyramid/registry.py +++ b/pyramid/registry.py @@ -129,10 +129,10 @@ class Introspector(object): values = category.values() values = sorted(set(values), key=sort_key) return [ - {'introspectable':intr, - 'related':self.related(intr)} - for intr in values - ] + {'introspectable': intr, + 'related': self.related(intr)} + for intr in values + ] def categorized(self, sort_key=None): L = [] diff --git a/pyramid/renderers.py b/pyramid/renderers.py index e3d11515d..42296bad1 100644 --- a/pyramid/renderers.py +++ b/pyramid/renderers.py @@ -145,25 +145,22 @@ def render_to_response(renderer_name, return result +_marker = object() + @contextlib.contextmanager def temporary_response(request): """ Temporarily delete request.response and restore it afterward. """ - saved_response = None - # save the current response, preventing the renderer from affecting it attrs = request.__dict__ if request is not None else {} - if 'response' in attrs: - saved_response = attrs['response'] - del attrs['response'] - - yield - - # restore the original response, overwriting any changes - if saved_response is not None: - attrs['response'] = saved_response - elif 'response' in attrs: - del attrs['response'] + saved_response = attrs.pop('response', _marker) + try: + yield + finally: + if saved_response is not _marker: + attrs['response'] = saved_response + elif 'response' in attrs: + del attrs['response'] def get_renderer(renderer_name, package=None): """ Return the renderer object for the renderer ``renderer_name``. diff --git a/pyramid/request.py b/pyramid/request.py index 13b8cd339..45d936cef 100644 --- a/pyramid/request.py +++ b/pyramid/request.py @@ -22,7 +22,7 @@ from pyramid.compat import ( from pyramid.decorator import reify from pyramid.i18n import LocalizerRequestMixin -from pyramid.response import Response, _get_response_factory +from pyramid.response import Response, _get_response_factory from pyramid.security import ( AuthenticationAPIMixin, AuthorizationAPIMixin, @@ -37,8 +37,14 @@ class TemplateContext(object): pass class CallbackMethodsMixin(object): - response_callbacks = None - finished_callbacks = None + @reify + def finished_callbacks(self): + return deque() + + @reify + def response_callbacks(self): + return deque() + def add_response_callback(self, callback): """ Add a callback to the set of callbacks to be called by the @@ -64,7 +70,7 @@ class CallbackMethodsMixin(object): called if an exception happens in application code, or if the response object returned by :term:`view` code is invalid. - All response callbacks are called *after* the tweens and + All response callbacks are called *after* the tweens and *before* the :class:`pyramid.events.NewResponse` event is sent. Errors raised by callbacks are not handled specially. They @@ -76,11 +82,7 @@ class CallbackMethodsMixin(object): See also :ref:`using_response_callbacks`. """ - callbacks = self.response_callbacks - if callbacks is None: - callbacks = deque() - callbacks.append(callback) - self.response_callbacks = callbacks + self.response_callbacks.append(callback) def _process_response_callbacks(self, response): callbacks = self.response_callbacks @@ -135,12 +137,7 @@ class CallbackMethodsMixin(object): See also :ref:`using_finished_callbacks`. """ - - callbacks = self.finished_callbacks - if callbacks is None: - callbacks = deque() - callbacks.append(callback) - self.finished_callbacks = callbacks + self.finished_callbacks.append(callback) def _process_finished_callbacks(self): callbacks = self.finished_callbacks @@ -237,7 +234,7 @@ class Request( def json_body(self): return json.loads(text_(self.body, self.charset)) - + 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 @@ -251,9 +248,10 @@ def route_request_iface(name, bases=()): iface.combined = InterfaceClass( '%s_combined_IRequest' % name, bases=(iface, IRequest), - __doc__ = 'route_request_iface-generated combined interface') + __doc__='route_request_iface-generated combined interface') return iface + def add_global_response_headers(request, headerlist): def add_headers(request, response): for k, v in headerlist: diff --git a/pyramid/scaffolds/copydir.py b/pyramid/scaffolds/copydir.py index 3b871dc19..4471777f2 100644 --- a/pyramid/scaffolds/copydir.py +++ b/pyramid/scaffolds/copydir.py @@ -15,6 +15,7 @@ from pyramid.compat import ( fsenc = sys.getfilesystemencoding() + class SkipTemplate(Exception): """ Raised to indicate that the template should not be copied over. @@ -61,7 +62,7 @@ def copy_dir(source, dest, vars, verbosity, simulate, indent=0, names = sorted(pkg_resources.resource_listdir(source[0], source[1])) else: names = sorted(os.listdir(source)) - pad = ' '*(indent*2) + pad = ' ' * (indent * 2) if not os.path.exists(dest): if verbosity >= 1: out('%sCreating %s/' % (pad, dest)) @@ -90,7 +91,7 @@ def copy_dir(source, dest, vars, verbosity, simulate, indent=0, if verbosity: out('%sRecursing into %s' % (pad, os.path.basename(full))) copy_dir((source[0], full), dest_full, vars, verbosity, simulate, - indent=indent+1, sub_vars=sub_vars, + indent=indent + 1, sub_vars=sub_vars, interactive=interactive, overwrite=overwrite, template_renderer=template_renderer, out_=out_) continue @@ -98,7 +99,7 @@ def copy_dir(source, dest, vars, verbosity, simulate, indent=0, if verbosity: out('%sRecursing into %s' % (pad, os.path.basename(full))) copy_dir(full, dest_full, vars, verbosity, simulate, - indent=indent+1, sub_vars=sub_vars, + indent=indent + 1, sub_vars=sub_vars, interactive=interactive, overwrite=overwrite, template_renderer=template_renderer, out_=out_) continue @@ -185,14 +186,14 @@ def query_interactive(src_fn, dest_fn, src_content, dest_content, dest_content.splitlines(), src_content.splitlines(), dest_fn, src_fn)) - added = len([l for l in u_diff if l.startswith('+') - and not l.startswith('+++')]) - removed = len([l for l in u_diff if l.startswith('-') - and not l.startswith('---')]) + added = len([l for l in u_diff if l.startswith('+') and + not l.startswith('+++')]) + removed = len([l for l in u_diff if l.startswith('-') and + not l.startswith('---')]) if added > removed: - msg = '; %i lines added' % (added-removed) + msg = '; %i lines added' % (added - removed) elif removed > added: - msg = '; %i lines removed' % (removed-added) + msg = '; %i lines removed' % (removed - added) else: msg = '' out('Replace %i bytes with %i bytes (%i/%i lines changed%s)' % ( diff --git a/pyramid/scaffolds/tests.py b/pyramid/scaffolds/tests.py index db828759e..49358c1cf 100644 --- a/pyramid/scaffolds/tests.py +++ b/pyramid/scaffolds/tests.py @@ -10,8 +10,9 @@ try: except ImportError: import httplib + class TemplateTest(object): - def make_venv(self, directory): # pragma: no cover + def make_venv(self, directory): # pragma: no cover import virtualenv from virtualenv import Logger logger = Logger([(Logger.level_for_integer(2), sys.stdout)]) @@ -20,7 +21,8 @@ class TemplateTest(object): site_packages=False, clear=False, unzip_setuptools=True) - def install(self, tmpl_name): # pragma: no cover + + def install(self, tmpl_name): # pragma: no cover try: self.old_cwd = os.getcwd() self.directory = tempfile.mkdtemp() @@ -58,7 +60,7 @@ class TemplateTest(object): if hastoolbar: assert toolbarchunk in data, ininame else: - assert not toolbarchunk in data, ininame + assert toolbarchunk not in data, ininame finally: proc.terminate() finally: diff --git a/pyramid/scaffolds/zodb/+package+/models.py b/pyramid/scaffolds/zodb/+package+/models.py index a94b36ef4..e5aa3e9f7 100644 --- a/pyramid/scaffolds/zodb/+package+/models.py +++ b/pyramid/scaffolds/zodb/+package+/models.py @@ -6,7 +6,7 @@ class MyModel(PersistentMapping): def appmaker(zodb_root): - if not 'app_root' in zodb_root: + if 'app_root' not in zodb_root: app_root = MyModel() zodb_root['app_root'] = app_root import transaction diff --git a/pyramid/scripts/pcreate.py b/pyramid/scripts/pcreate.py index d2c5f8c27..f6376f575 100644 --- a/pyramid/scripts/pcreate.py +++ b/pyramid/scripts/pcreate.py @@ -132,7 +132,7 @@ class PCreateCommand(object): for scaffold in scaffolds: self.out(' %s:%s %s' % ( scaffold.name, - ' '*(max_name-len(scaffold.name)), scaffold.summary)) + ' ' * (max_name - len(scaffold.name)), scaffold.summary)) else: self.out('No scaffolds available') return 0 diff --git a/pyramid/scripts/prequest.py b/pyramid/scripts/prequest.py index 34eeadf32..61e422c64 100644 --- a/pyramid/scripts/prequest.py +++ b/pyramid/scripts/prequest.py @@ -52,8 +52,10 @@ class PRequestCommand(object): parser.add_option( '-n', '--app-name', dest='app_name', - metavar= 'NAME', - help="Load the named application from the config file (default 'main')", + metavar='NAME', + help=( + "Load the named application from the config file (default 'main')" + ), type="string", ) parser.add_option( @@ -62,8 +64,10 @@ class PRequestCommand(object): metavar='NAME:VALUE', type='string', action='append', - help="Header to add to request (you can use this option multiple times)" - ) + help=( + "Header to add to request (you can use this option multiple times)" + ), + ) parser.add_option( '-d', '--display-headers', dest='display_headers', @@ -167,7 +171,7 @@ class PRequestCommand(object): if name.lower() == 'content-type': name = 'CONTENT_TYPE' else: - name = 'HTTP_'+name.upper().replace('-', '_') + name = 'HTTP_' + name.upper().replace('-', '_') environ[name] = value request = Request.blank(path, environ=environ) diff --git a/pyramid/scripts/pserve.py b/pyramid/scripts/pserve.py index 57e4ab012..e97bdcd48 100644 --- a/pyramid/scripts/pserve.py +++ b/pyramid/scripts/pserve.py @@ -143,7 +143,7 @@ class PServeCommand(object): default=default_verbosity, dest='verbose', action='count', - help="Set verbose level (default "+str(default_verbosity)+")") + help="Set verbose level (default " + str(default_verbosity) + ")") parser.add_option( '-q', '--quiet', action='store_const', @@ -188,15 +188,17 @@ class PServeCommand(object): print(msg) def get_options(self): - if (len(self.args) > 1 - and self.args[1] in self.possible_subcommands): + if ( + len(self.args) > 1 and + self.args[1] in self.possible_subcommands + ): restvars = self.args[2:] else: restvars = self.args[1:] return parse_vars(restvars) - def run(self): # pragma: no cover + def run(self): # pragma: no cover if self.options.stop_daemon: return self.stop_daemon() @@ -213,8 +215,10 @@ class PServeCommand(object): return 2 app_spec = self.args[0] - if (len(self.args) > 1 - and self.args[1] in self.possible_subcommands): + if ( + len(self.args) > 1 and + self.args[1] in self.possible_subcommands + ): cmd = self.args[1] else: cmd = None @@ -299,8 +303,10 @@ class PServeCommand(object): self.out(str(ex)) return 2 - if (self.options.monitor_restart - and not os.environ.get(self._monitor_environ_key)): + if ( + self.options.monitor_restart and + not os.environ.get(self._monitor_environ_key) + ): return self.restart_with_monitor() if self.options.pid_file: @@ -568,7 +574,9 @@ class PServeCommand(object): def change_user_group(self, user, group): # pragma: no cover if not user and not group: return - import pwd, grp + import pwd + import grp + uid = gid = None if group: try: @@ -602,6 +610,7 @@ class PServeCommand(object): if uid: os.setuid(uid) + class LazyWriter(object): """ @@ -762,11 +771,12 @@ class _methodwrapper(object): self.type = type def __call__(self, *args, **kw): - assert not 'self' in kw and not 'cls' in kw, ( + assert 'self' not in kw and 'cls' not in kw, ( "You cannot use 'self' or 'cls' arguments to a " "classinstancemethod") return self.func(*((self.obj, self.type) + args), **kw) + class Monitor(object): # pragma: no cover """ A file monitor and server restarter. @@ -860,7 +870,7 @@ class Monitor(object): # pragma: no cover continue if filename.endswith('.pyc') and os.path.exists(filename[:-1]): mtime = max(os.stat(filename[:-1]).st_mtime, mtime) - if not filename in self.module_mtimes: + if filename not in self.module_mtimes: self.module_mtimes[filename] = mtime elif self.module_mtimes[filename] < mtime: print("%s changed; reloading..." % filename) diff --git a/pyramid/scripts/ptweens.py b/pyramid/scripts/ptweens.py index ad52d5d8f..a7aa009da 100644 --- a/pyramid/scripts/ptweens.py +++ b/pyramid/scripts/ptweens.py @@ -42,7 +42,7 @@ class PTweensCommand(object): def _get_tweens(self, registry): from pyramid.config import Configurator - config = Configurator(registry = registry) + config = Configurator(registry=registry) return config.registry.queryUtility(ITweens) def out(self, msg): # pragma: no cover @@ -52,7 +52,7 @@ class PTweensCommand(object): def show_chain(self, chain): fmt = '%-10s %-65s' self.out(fmt % ('Position', 'Name')) - self.out(fmt % ('-'*len('Position'), '-'*len('Name'))) + self.out(fmt % ('-' * len('Position'), '-' * len('Name'))) self.out(fmt % ('-', INGRESS)) for pos, (name, _) in enumerate(chain): self.out(fmt % (pos, name)) diff --git a/pyramid/scripts/pviews.py b/pyramid/scripts/pviews.py index 4922c3a70..9018eddb4 100644 --- a/pyramid/scripts/pviews.py +++ b/pyramid/scripts/pviews.py @@ -143,10 +143,8 @@ class PViewsCommand(object): if traverser is None: traverser = ResourceTreeTraverser(root) tdict = traverser(request) - context, view_name, subpath, traversed, vroot, vroot_path =( - tdict['context'], tdict['view_name'], tdict['subpath'], - tdict['traversed'], tdict['virtual_root'], - tdict['virtual_root_path']) + context, view_name = (tdict['context'], tdict['view_name']) + attrs.update(tdict) # find a view callable @@ -218,7 +216,7 @@ class PViewsCommand(object): if not IMultiView.providedBy(view_wrapper): # single view for this route, so repeat call without route data del request_attrs['matched_route'] - self.output_view_info(view_wrapper, level+1) + self.output_view_info(view_wrapper, level + 1) else: self.out("%sView:" % indent) self.out("%s-----" % indent) diff --git a/pyramid/static.py b/pyramid/static.py index 4ff02f798..cb78feb9b 100644 --- a/pyramid/static.py +++ b/pyramid/static.py @@ -107,12 +107,14 @@ class static_view(object): raise HTTPNotFound('Out of bounds: %s' % request.url) if self.package_name: # package resource - - resource_path ='%s/%s' % (self.docroot.rstrip('/'), path) + resource_path = '%s/%s' % (self.docroot.rstrip('/'), path) if resource_isdir(self.package_name, resource_path): if not request.path_url.endswith('/'): self.add_slash_redirect(request) - resource_path = '%s/%s' % (resource_path.rstrip('/'),self.index) + resource_path = '%s/%s' % ( + resource_path.rstrip('/'), self.index + ) + if not resource_exists(self.package_name, resource_path): raise HTTPNotFound(request.url) filepath = resource_filename(self.package_name, resource_path) diff --git a/pyramid/testing.py b/pyramid/testing.py index 772914f3b..58dcb0b59 100644 --- a/pyramid/testing.py +++ b/pyramid/testing.py @@ -154,9 +154,10 @@ class DummyTemplateRenderer(object): if myval != v: raise AssertionError( '\nasserted value for %s: %r\nactual value: %r' % ( - k, v, myval)) + k, v, myval)) return True + class DummyResource: """ A dummy :app:`Pyramid` :term:`resource` object.""" def __init__(self, __name__=None, __parent__=None, __provides__=None, @@ -384,11 +385,12 @@ class DummyRequest( @reify def response(self): - f = _get_response_factory(self.registry) + f = _get_response_factory(self.registry) return f(self) have_zca = True + def setUp(registry=None, request=None, hook_zca=True, autocommit=True, settings=None, package=None): """ @@ -578,10 +580,13 @@ def skip_on(*platforms): # pragma: no cover skip = True if platform == 'py3' and PY3: skip = True + def decorator(func): if isinstance(func, class_types): - if skip: return None - else: return func + if skip: + return None + else: + return func else: def wrapper(*args, **kw): if skip: diff --git a/pyramid/tests/test_renderers.py b/pyramid/tests/test_renderers.py index f8b5bfca0..61a798ad1 100644 --- a/pyramid/tests/test_renderers.py +++ b/pyramid/tests/test_renderers.py @@ -592,6 +592,48 @@ class Test_render_to_response(unittest.TestCase): self.assertEqual(result.body, b'{"a": 1}') self.assertFalse('response' in request.__dict__) +class Test_temporary_response(unittest.TestCase): + def _callFUT(self, request): + from pyramid.renderers import temporary_response + return temporary_response(request) + + def test_restores_response(self): + request = testing.DummyRequest() + orig_response = request.response + with self._callFUT(request): + request.response = object() + self.assertEqual(request.response, orig_response) + + def test_restores_response_on_exception(self): + request = testing.DummyRequest() + orig_response = request.response + try: + with self._callFUT(request): + request.response = object() + raise RuntimeError() + except RuntimeError: + self.assertEqual(request.response, orig_response) + else: # pragma: no cover + self.fail("RuntimeError not raised") + + def test_restores_response_to_none(self): + request = testing.DummyRequest(response=None) + with self._callFUT(request): + request.response = object() + self.assertEqual(request.response, None) + + def test_deletes_response(self): + request = testing.DummyRequest() + with self._callFUT(request): + request.response = object() + self.assertTrue('response' not in request.__dict__) + + def test_does_not_delete_response_if_no_response_to_delete(self): + request = testing.DummyRequest() + with self._callFUT(request): + pass + self.assertTrue('response' not in request.__dict__) + class Test_get_renderer(unittest.TestCase): def setUp(self): self.config = testing.setUp() diff --git a/pyramid/tests/test_request.py b/pyramid/tests/test_request.py index 2c2298f26..c528b9174 100644 --- a/pyramid/tests/test_request.py +++ b/pyramid/tests/test_request.py @@ -120,7 +120,7 @@ class TestRequest(unittest.TestCase): def test_add_response_callback(self): inst = self._makeOne() - self.assertEqual(inst.response_callbacks, None) + self.assertEqual(len(inst.response_callbacks), 0) def callback(request, response): """ """ inst.add_response_callback(callback) @@ -171,7 +171,7 @@ class TestRequest(unittest.TestCase): def test_add_finished_callback(self): inst = self._makeOne() - self.assertEqual(inst.finished_callbacks, None) + self.assertEqual(len(inst.finished_callbacks), 0) def callback(request): """ """ inst.add_finished_callback(callback) diff --git a/pyramid/traversal.py b/pyramid/traversal.py index a38cf271e..db73d13fc 100644 --- a/pyramid/traversal.py +++ b/pyramid/traversal.py @@ -14,10 +14,6 @@ from pyramid.interfaces import ( VH_ROOT_KEY, ) -with warnings.catch_warnings(): - warnings.filterwarnings('ignore') - from pyramid.interfaces import IContextURL - from pyramid.compat import ( PY3, native_, @@ -35,6 +31,10 @@ from pyramid.exceptions import URLDecodeError from pyramid.location import lineage from pyramid.threadlocal import get_current_registry +with warnings.catch_warnings(): + warnings.filterwarnings('ignore') + from pyramid.interfaces import IContextURL + empty = text_('') def find_root(resource): @@ -664,10 +664,10 @@ class ResourceTreeTraverser(object): if VH_ROOT_KEY in environ: # HTTP_X_VHM_ROOT - vroot_path = decode_path_info(environ[VH_ROOT_KEY]) + vroot_path = decode_path_info(environ[VH_ROOT_KEY]) vroot_tuple = split_path_info(vroot_path) vpath = vroot_path + path # both will (must) be unicode or asciistr - vroot_idx = len(vroot_tuple) -1 + vroot_idx = len(vroot_tuple) - 1 else: vroot_tuple = () vpath = path @@ -689,34 +689,34 @@ class ResourceTreeTraverser(object): vpath_tuple = split_path_info(vpath) for segment in vpath_tuple: if segment[:2] == view_selector: - return {'context':ob, - 'view_name':segment[2:], - 'subpath':vpath_tuple[i+1:], - 'traversed':vpath_tuple[:vroot_idx+i+1], - 'virtual_root':vroot, - 'virtual_root_path':vroot_tuple, - 'root':root} + return {'context': ob, + 'view_name': segment[2:], + 'subpath': vpath_tuple[i + 1:], + 'traversed': vpath_tuple[:vroot_idx + i + 1], + 'virtual_root': vroot, + 'virtual_root_path': vroot_tuple, + 'root': root} try: getitem = ob.__getitem__ except AttributeError: - return {'context':ob, - 'view_name':segment, - 'subpath':vpath_tuple[i+1:], - 'traversed':vpath_tuple[:vroot_idx+i+1], - 'virtual_root':vroot, - 'virtual_root_path':vroot_tuple, - 'root':root} + return {'context': ob, + 'view_name': segment, + 'subpath': vpath_tuple[i + 1:], + 'traversed': vpath_tuple[:vroot_idx + i + 1], + 'virtual_root': vroot, + 'virtual_root_path': vroot_tuple, + 'root': root} try: next = getitem(segment) except KeyError: - return {'context':ob, - 'view_name':segment, - 'subpath':vpath_tuple[i+1:], - 'traversed':vpath_tuple[:vroot_idx+i+1], - 'virtual_root':vroot, - 'virtual_root_path':vroot_tuple, - 'root':root} + return {'context': ob, + 'view_name': segment, + 'subpath': vpath_tuple[i + 1:], + 'traversed': vpath_tuple[:vroot_idx + i + 1], + 'virtual_root': vroot, + 'virtual_root_path': vroot_tuple, + 'root': root} if i == vroot_idx: vroot = next ob = next diff --git a/pyramid/url.py b/pyramid/url.py index a0f3d7f2f..b004c40ec 100644 --- a/pyramid/url.py +++ b/pyramid/url.py @@ -606,10 +606,11 @@ class URLMethodsMixin(object): if local_url is not None: # the resource handles its own url generation d = dict( - virtual_path = virtual_path, - physical_path = url_adapter.physical_path, - app_url = app_url, - ) + virtual_path=virtual_path, + physical_path=url_adapter.physical_path, + app_url=app_url, + ) + # allow __resource_url__ to punt by returning None resource_url = local_url(self, d) @@ -698,7 +699,7 @@ class URLMethodsMixin(object): """ if not os.path.isabs(path): - if not ':' in path: + if ':' not in path: # if it's not a package:relative/name and it's not an # /absolute/path it's a relative/path; this means its relative # to the package in which the caller's module is defined. @@ -743,7 +744,7 @@ class URLMethodsMixin(object): to ``static_path`` will be ignored. """ if not os.path.isabs(path): - if not ':' in path: + if ':' not in path: # if it's not a package:relative/name and it's not an # /absolute/path it's a relative/path; this means its relative # to the package in which the caller's module is defined. @@ -884,6 +885,7 @@ def resource_url(resource, request, *elements, **kw): model_url = resource_url # b/w compat (forever) + def static_url(path, request, **kw): """ This is a backwards compatibility function. Its result is the same as @@ -894,7 +896,7 @@ def static_url(path, request, **kw): See :meth:`pyramid.request.Request.static_url` for more information. """ if not os.path.isabs(path): - if not ':' in path: + if ':' not in path: # if it's not a package:relative/name and it's not an # /absolute/path it's a relative/path; this means its relative # to the package in which the caller's module is defined. @@ -902,6 +904,7 @@ def static_url(path, request, **kw): path = '%s:%s' % (package.__name__, path) return request.static_url(path, **kw) + def static_path(path, request, **kw): """ This is a backwards compatibility function. Its result is the same as @@ -912,7 +915,7 @@ def static_path(path, request, **kw): See :meth:`pyramid.request.Request.static_path` for more information. """ if not os.path.isabs(path): - if not ':' in path: + if ':' not in path: # if it's not a package:relative/name and it's not an # /absolute/path it's a relative/path; this means its relative # to the package in which the caller's module is defined. diff --git a/pyramid/util.py b/pyramid/util.py index 4a722b381..1ae7e6afc 100644 --- a/pyramid/util.py +++ b/pyramid/util.py @@ -16,7 +16,6 @@ from pyramid.exceptions import ( ) from pyramid.compat import ( - iteritems_, is_nonstr_iter, integer_types, string_types, @@ -28,12 +27,14 @@ from pyramid.compat import ( from pyramid.interfaces import IActionInfo from pyramid.path import DottedNameResolver as _DottedNameResolver + class DottedNameResolver(_DottedNameResolver): def __init__(self, package=None): # default to package = None for bw compat return _DottedNameResolver.__init__(self, package) _marker = object() + class InstancePropertyHelper(object): """A helper object for assigning properties and descriptors to instances. It is not normally possible to do this because descriptors must be @@ -446,7 +447,7 @@ class TopologicalSorter(object): order.append((a, b)) def add_node(node): - if not node in graph: + if node not in graph: roots.append(node) graph[node] = [0] # 0 = number of arcs coming into this node @@ -519,7 +520,7 @@ def viewdefaults(wrapped): view = self.maybe_dotted(view) if inspect.isclass(view): defaults = getattr(view, '__view_defaults__', {}).copy() - if not '_backframes' in kw: + if '_backframes' not in kw: kw['_backframes'] = 1 # for action_method defaults.update(kw) return wrapped(self, *arg, **defaults) diff --git a/pyramid/view.py b/pyramid/view.py index fd020c7ea..005e81148 100644 --- a/pyramid/view.py +++ b/pyramid/view.py @@ -56,7 +56,7 @@ def render_view_to_response(context, request, name='', secure=True): context, context_iface, name, - secure = secure, + secure=secure, ) return response # NB: might be None @@ -272,7 +272,7 @@ class AppendSlashNotFoundViewFactory(object): qs = request.query_string if qs: qs = '?' + qs - return self.redirect_class(location=request.path+'/'+qs) + return self.redirect_class(location=request.path + '/' + qs) return self.notfound_view(context, request) append_slash_notfound_view = AppendSlashNotFoundViewFactory() @@ -451,9 +451,9 @@ def _find_views( view_types=None, view_classifier=None, ): - if view_types is None: + if view_types is None: view_types = (IView, ISecuredView, IMultiView) - if view_classifier is None: + if view_classifier is None: view_classifier = IViewClassifier registered = registry.adapters.registered cache = registry._view_lookup_cache @@ -2,3 +2,4 @@ Sphinx >= 1.2.3 repoze.sphinx.autointerface repoze.lru pylons_sphinx_latesturl +pylons-sphinx-themes
\ No newline at end of file @@ -13,3 +13,7 @@ docs = develop easy_install pyramid[docs] [bdist_wheel] universal = 1 +[flake8] +ignore = E301,E302,E731,E261,E123,E121,E128,E129,E125,W291,E501,W293,E303,W391,E266,E231,E201,E202,E127,E262,E265 +exclude = pyramid/tests/,pyramid/compat.py,pyramid/resource.py +show-source = True @@ -59,6 +59,7 @@ docs_extras = [ 'Sphinx >= 1.2.3', 'docutils', 'repoze.sphinx.autointerface', + 'pylons-sphinx-themes >= 0.3', ] testing_extras = tests_require + [ @@ -68,7 +69,7 @@ testing_extras = tests_require + [ ] setup(name='pyramid', - version='1.6.dev0', + version='1.7.dev0', description='The Pyramid Web Framework, a Pylons project', long_description=README + '\n\n' + CHANGES, classifiers=[ @@ -1,6 +1,6 @@ [tox] envlist = - py26,py27,py32,py33,py34,pypy,pypy3, + py26,py27,py32,py33,py34,pypy,pypy3,pep8, {py2,py3}-docs, {py2,py3}-cover,coverage, @@ -22,6 +22,16 @@ commands = pip install pyramid[testing] nosetests --with-xunit --xunit-file=nosetests-{envname}.xml {posargs:} +[testenv:pep8] +basepython = python3.4 +commands = + flake8 pyramid/ +deps = + flake8 + +# we separate coverage into its own testenv because a) "last run wins" wrt +# cobertura jenkins reporting and b) pypy and jython can't handle any +# combination of versions of coverage and nosexcover that i can find. [testenv:py2-cover] commands = pip install pyramid[testing] @@ -42,17 +52,17 @@ setenv = whitelist_externals = make commands = pip install pyramid[docs] - make -C docs html + make -C docs html epub BUILDDIR={envdir} [testenv:py3-docs] whitelist_externals = make commands = pip install pyramid[docs] - make -C docs html + make -C docs html epub BUILDDIR={envdir} [testenv:coverage] basepython = python3.4 -commands = +commands = coverage erase coverage combine coverage xml |
