diff options
| author | Chris McDonough <chrism@plope.com> | 2010-12-18 04:00:31 -0500 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2010-12-18 04:00:31 -0500 |
| commit | 3e2f12520381495aa64c24bdbe85d72b0746e16c (patch) | |
| tree | d68e6ab7292bcf7bd92c4616415b4682dbaca9ac | |
| parent | c0c7b59edbf0d5572f3438918b3157a3f921f890 (diff) | |
| download | pyramid-3e2f12520381495aa64c24bdbe85d72b0746e16c.tar.gz pyramid-3e2f12520381495aa64c24bdbe85d72b0746e16c.tar.bz2 pyramid-3e2f12520381495aa64c24bdbe85d72b0746e16c.zip | |
resource -> asset
| -rw-r--r-- | docs/api/testing.rst | 4 | ||||
| -rw-r--r-- | docs/glossary.rst | 96 | ||||
| -rw-r--r-- | docs/latexindex.rst | 2 | ||||
| -rw-r--r-- | docs/zcml.rst | 2 | ||||
| -rw-r--r-- | pyramid/authorization.py | 2 | ||||
| -rw-r--r-- | pyramid/chameleon_text.py | 8 | ||||
| -rw-r--r-- | pyramid/chameleon_zpt.py | 8 | ||||
| -rw-r--r-- | pyramid/config.py | 60 | ||||
| -rw-r--r-- | pyramid/interfaces.py | 2 | ||||
| -rw-r--r-- | pyramid/location.py | 32 | ||||
| -rw-r--r-- | pyramid/request.py | 11 | ||||
| -rw-r--r-- | pyramid/router.py | 8 | ||||
| -rw-r--r-- | pyramid/security.py | 4 | ||||
| -rw-r--r-- | pyramid/settings.py | 2 | ||||
| -rw-r--r-- | pyramid/static.py | 14 | ||||
| -rw-r--r-- | pyramid/testing.py | 50 | ||||
| -rw-r--r-- | pyramid/tests/test_authorization.py | 2 | ||||
| -rw-r--r-- | pyramid/tests/test_testing.py | 70 | ||||
| -rw-r--r-- | pyramid/traversal.py | 2 | ||||
| -rw-r--r-- | pyramid/url.py | 12 | ||||
| -rw-r--r-- | pyramid/view.py | 10 |
21 files changed, 204 insertions, 197 deletions
diff --git a/docs/api/testing.rst b/docs/api/testing.rst index fc4b76cc7..fdcdadee8 100644 --- a/docs/api/testing.rst +++ b/docs/api/testing.rst @@ -7,7 +7,7 @@ .. autofunction:: registerDummySecurityPolicy - .. autofunction:: registerModels + .. autofunction:: registerResources .. autofunction:: registerEventListener @@ -31,7 +31,7 @@ .. autofunction:: cleanUp - .. autoclass:: DummyModel + .. autoclass:: DummyResource :members: .. autoclass:: DummyRequest diff --git a/docs/glossary.rst b/docs/glossary.rst index 2494a6cdf..68d89d381 100644 --- a/docs/glossary.rst +++ b/docs/glossary.rst @@ -38,20 +38,20 @@ Glossary pkg_resources A module which ships with :term:`setuptools` that provides an API - for addressing "resource files" within Python packages. Resource + for addressing "asset files" within Python packages. Asset files are static files, template files, etc; basically anything non-Python-source that lives in a Python package can be considered - a resource file. See also `PkgResources + a asset file. See also `PkgResources <http://peak.telecommunity.com/DevCenter/PkgResources>`_ - resource + asset Any file contained within a Python :term:`package` which is *not* a Python source code file. - resource specification + asset specification A colon-delimited identifier for a :term:`resource`. The colon separates a Python :term:`package` name from a package subpath. - For example, the resource specification + For example, the asset specification ``my.package:static/baz.css`` identifies the file named ``baz.css`` in the ``static`` subdirectory of the ``my.package`` Python :term:`package`. @@ -120,7 +120,7 @@ Glossary string (which implies the :term:`default view`). Default view - The default view of a model is the view invoked when the + The default view of a resource is the view invoked when the :term:`view name` is the empty string (``''``). This is the case when :term:`traversal` exhausts the path elements in the PATH_INFO of a request before it returns a :term:`context`. @@ -131,25 +131,24 @@ Glossary Python. `virtualenv <http://pypi.python.org/pypi/virtualenv>`_ was created by Ian Bicking. - model - An object representing data in the system. If :mod:`traversal` is - used, a model is a node in the object graph traversed by the - system. When traversal is used, a model instance becomes the - :term:`context` of a :term:`view`. If :mod:`url dispatch` is - used, a single :term:`context` is generated for each request and - is used as the context of a view: this object is also technically - a "model" in :app:`Pyramid` terms, although this terminology - can be a bit confusing: see :ref:`model_traversal_confusion`. + resource + An object representing a node in the resource tree of an application. + If :mod:`traversal` is used, a resource is an element in the resource + tree traversed by the system. When traversal is used, a resource + becomes the :term:`context` of a :term:`view`. If :mod:`url dispatch` + is used, a single resource is generated for each request and is + used as the context of a view. traversal - The act of descending "down" a graph of model objects from a root - model in order to find a :term:`context`. The :app:`Pyramid` - :term:`router` performs traversal of model objects when a - :term:`root factory` is specified. See the - :ref:`traversal_chapter` chapter for more information. Traversal - can be performed *instead* of :term:`URL dispatch` or can be - combined *with* URL dispatch. See :ref:`hybrid_chapter` for more - information about combining traversal and URL dispatch (advanced). + + The act of descending "up" a tree of resource objects from a root + resource in order to find a :term:`context`. The :app:`Pyramid` + :term:`router` performs traversal of resource objects when a :term:`root + factory` is specified. See the :ref:`traversal_chapter` chapter for + more information. Traversal can be performed *instead* of :term:`URL + dispatch` or can be combined *with* URL dispatch. See + :ref:`hybrid_chapter` for more information about combining traversal and + URL dispatch (advanced). router The :term:`WSGI` application created when you start a @@ -159,7 +158,7 @@ Glossary :app:`Pyramid` application. URL dispatch - An alternative to graph traversal as a mechanism for locating a + An alternative to :term:`traversal` as a mechanism for locating a :term:`context` for a :term:`view`. When you use a :term:`route` in your :app:`Pyramid` application via a :term:`route configuration`, you are using URL dispatch. See the @@ -167,19 +166,19 @@ Glossary context An object in the system that is found during :term:`traversal` or - :term:`URL dispatch` based on URL data; if it's found via - traversal, it's usually a :term:`model` object that is part of an - object graph; if it's found via :term:`URL dispatch`, it's a - object manufactured on behalf of the route's "factory". A context - becomes the subject of a :term:`view`, and typically has security - information attached to it. See the :ref:`traversal_chapter` - chapter and the :ref:`urldispatch_chapter` chapter for more - information about how a URL is resolved to a context. + :term:`URL dispatch` based on URL data; if it's found via traversal, + it's usually a :term:`resource` object that is part of a resource tree; + if it's found via :term:`URL dispatch`, it's a object manufactured on + behalf of the route's "factory". A context becomes the subject of a + :term:`view`, and typically has security information attached to it. + See the :ref:`traversal_chapter` chapter and the + :ref:`urldispatch_chapter` chapter for more information about how a URL + is resolved to a context. application registry A registry of configuration information consulted by :app:`Pyramid` while servicing an application. An application - registry maps model types to views, as well as housing other + registry maps resource types to views, as well as housing other application-specific component registrations. Every :app:`Pyramid` application has one (and only one) application registry. @@ -189,20 +188,19 @@ Glossary text, XML, or HTML when rendered. location - The path to an object in an object graph. See :ref:`location_aware` - for more information about how to make a model object *location-aware*. + The path to an object in a resource tree. See :ref:`location_aware` for + more information about how to make a resource object *location-aware*. permission - A string or unicode object that represents an action being taken - against a context. A permission is associated with a view name - and a model type by the developer. Models are decorated with - security declarations (e.g. an :term:`ACL`), which reference these - tokens also. Permissions are used by the active to security - policy to match the view permission against the model's statements - about which permissions are granted to which principal in a - context in order to to answer the question "is this user allowed - to do this". Examples of permissions: ``read``, or - ``view_blog_entries``. + A string or unicode object that represents an action being taken against + a context. A permission is associated with a view name and a resource + type by the developer. Resources are decorated with security + declarations (e.g. an :term:`ACL`), which reference these tokens also. + Permissions are used by the active to security policy to match the view + permission against the resources's statements about which permissions + are granted to which principal in a context in order to to answer the + question "is this user allowed to do this". Examples of permissions: + ``read``, or ``view_blog_entries``. default permission A :term:`permission` which is registered as the default for an @@ -225,9 +223,9 @@ Glossary ACL An *access control list*. An ACL is a sequence of :term:`ACE` - tuples. An ACL is attached to a model instance. An example of an + tuples. An ACL is attached to a resource instance. An example of an ACL is ``[ (Allow, 'bob', 'read'), (Deny, 'fred', 'write')]``. If - an ACL is attached to a model instance, and that model instance is + an ACL is attached to a resource instance, and that resource is findable via the context, it will be consulted any active security policy to determine wither a particular request can be fulfilled given the :term:`authentication` information in the request. @@ -416,7 +414,7 @@ Glossary interface A `Zope interface <http://pypi.python.org/pypi/zope.interface>`_ object. In :app:`Pyramid`, an interface may be attached to a - :term:`model` object or a :term:`request` object in order to + :term:`resource` object or a :term:`request` object in order to identify that the object is "of a type". Interfaces are used internally by :app:`Pyramid` to perform view lookups and other policy lookups. The ability to make use of an interface is @@ -476,7 +474,7 @@ Glossary :app:`Pyramid` to form a workflow system. virtual root - A model object representing the "virtual" root of a request; this + A resource object representing the "virtual" root of a request; this is typically the physical root object (the object returned by the application root factory) unless :ref:`vhosting_chapter` is in use. diff --git a/docs/latexindex.rst b/docs/latexindex.rst index 81788035a..09e449fe3 100644 --- a/docs/latexindex.rst +++ b/docs/latexindex.rst @@ -119,6 +119,7 @@ ZCML Directive Reference zcml/aclauthorizationpolicy zcml/adapter zcml/authtktauthenticationpolicy + zcml/asset zcml/configure zcml/default_permission zcml/forbidden @@ -127,7 +128,6 @@ ZCML Directive Reference zcml/remoteuserauthenticationpolicy zcml/renderer zcml/repozewho1authenticationpolicy - zcml/resource zcml/route zcml/scan zcml/static diff --git a/docs/zcml.rst b/docs/zcml.rst index 5913f9460..e5bbe5d4b 100644 --- a/docs/zcml.rst +++ b/docs/zcml.rst @@ -13,6 +13,7 @@ documentation is organized alphabetically by directive name. zcml/aclauthorizationpolicy zcml/adapter zcml/authtktauthenticationpolicy + zcml/asset zcml/configure zcml/default_permission zcml/forbidden @@ -23,7 +24,6 @@ documentation is organized alphabetically by directive name. zcml/remoteuserauthenticationpolicy zcml/renderer zcml/repozewho1authenticationpolicy - zcml/resource zcml/route zcml/scan zcml/static diff --git a/pyramid/authorization.py b/pyramid/authorization.py index 4d2f3eb0e..f27369172 100644 --- a/pyramid/authorization.py +++ b/pyramid/authorization.py @@ -65,7 +65,7 @@ class ACLAuthorizationPolicy(object): permits access, return an instance of :class:`pyramid.security.ACLDenied` if not.""" - acl = '<No ACL found on any object in model lineage>' + acl = '<No ACL found on any object in resource lineage>' for location in lineage(context): try: diff --git a/pyramid/chameleon_text.py b/pyramid/chameleon_text.py index 6eb7af4d0..32896b8e9 100644 --- a/pyramid/chameleon_text.py +++ b/pyramid/chameleon_text.py @@ -71,7 +71,7 @@ def get_renderer(path): """ Return a callable object which can be used to render a :term:`Chameleon` text template using the template implied by the ``path`` argument. The ``path`` argument may be a - package-relative path, an absolute path, or a :term:`resource + package-relative path, an absolute path, or a :term:`asset specification`. .. warning:: This API is deprecated in :app:`Pyramid` 1.0. Use @@ -90,7 +90,7 @@ def get_template(path): """ Return the underyling object representing a :term:`Chameleon` text template using the template implied by the ``path`` argument. The ``path`` argument may be a package-relative path, an absolute - path, or a :term:`resource specification`. + path, or a :term:`asset specification`. .. warning:: This API is deprecated in :app:`Pyramid` 1.0. Use the ``implementation()`` method of a template renderer retrieved via @@ -109,7 +109,7 @@ deprecated( def render_template(path, **kw): """ Render a :term:`Chameleon` text template using the template implied by the ``path`` argument. The ``path`` argument may be a - package-relative path, an absolute path, or a :term:`resource + package-relative path, an absolute path, or a :term:`asset specification`. The arguments in ``*kw`` are passed as top-level names to the template, and so may be used within the template itself. Returns a string. @@ -130,7 +130,7 @@ deprecated( def render_template_to_response(path, **kw): """ Render a :term:`Chameleon` text template using the template implied by the ``path`` argument. The ``path`` argument may be a - package-relative path, an absolute path, or a :term:`resource + package-relative path, an absolute path, or a :term:`asset specification`. The arguments in ``*kw`` are passed as top-level names to the template, and so may be used within the template itself. Returns a :term:`Response` object with the body as the diff --git a/pyramid/chameleon_zpt.py b/pyramid/chameleon_zpt.py index 5c2d6f70f..f6093ea13 100644 --- a/pyramid/chameleon_zpt.py +++ b/pyramid/chameleon_zpt.py @@ -56,7 +56,7 @@ def get_renderer(path): """ Return a callable object which can be used to render a :term:`Chameleon` ZPT template using the template implied by the ``path`` argument. The ``path`` argument may be a - package-relative path, an absolute path, or a :term:`resource + package-relative path, an absolute path, or a :term:`asset specification`. .. warning:: This API is deprecated in :app:`Pyramid` 1.0. Use @@ -75,7 +75,7 @@ def get_template(path): """ Return the underyling object representing a :term:`Chameleon` ZPT template using the template implied by the ``path`` argument. The ``path`` argument may be a package-relative path, an absolute - path, or a :term:`resource specification`. + path, or a :term:`asset specification`. .. warning:: This API is deprecated in :app:`Pyramid` 1.0. Use the ``implementation()`` method of a template renderer retrieved via @@ -94,7 +94,7 @@ deprecated( def render_template(path, **kw): """ Render a :term:`Chameleon` ZPT template using the template implied by the ``path`` argument. The ``path`` argument may be a - package-relative path, an absolute path, or a :term:`resource + package-relative path, an absolute path, or a :term:`asset specification`. The arguments in ``*kw`` are passed as top-level names to the template, and so may be used within the template itself. Returns a string. @@ -115,7 +115,7 @@ deprecated( def render_template_to_response(path, **kw): """ Render a :term:`Chameleon` ZPT template using the template implied by the ``path`` argument. The ``path`` argument may be a - package-relative path, an absolute path, or a :term:`resource + package-relative path, an absolute path, or a :term:`asset specification`. The arguments in ``*kw`` are passed as top-level names to the template, and so may be used within the template itself. Returns a :term:`Response` object with the body as the diff --git a/pyramid/config.py b/pyramid/config.py index c82e15ae6..59c8706d0 100644 --- a/pyramid/config.py +++ b/pyramid/config.py @@ -850,7 +850,7 @@ class Configurator(object): def load_zcml(self, spec='configure.zcml', lock=threading.Lock()): """ Load configuration from a :term:`ZCML` file into the current configuration state. The ``spec`` argument is an - absolute filename, a relative filename, or a :term:`resource + absolute filename, a relative filename, or a :term:`asset specification`, defaulting to ``configure.zcml`` (relative to the package of the configurator's caller).""" package_name, filename = self._split_spec(spec) @@ -1063,7 +1063,7 @@ class Configurator(object): renderer This is either a single string term (e.g. ``json``) or a - string implying a path or :term:`resource specification` + string implying a path or :term:`asset specification` (e.g. ``templates/views.pt``) naming a :term:`renderer` implementation. If the ``renderer`` value does not contain a dot ``.``, the specified string will be used to look up a @@ -1088,9 +1088,9 @@ class Configurator(object): current :term:`package` of the Configurator), a path can be absolute, starting with a slash on UNIX or a drive letter prefix on Windows. The path can alternately be a - :term:`resource specification` in the form + :term:`asset specification` in the form ``some.dotted.package_name:relative/path``, making it - possible to address template resources which live in a + possible to address template assets which live in a separate package. The ``renderer`` attribute is optional. If it is not @@ -1474,11 +1474,10 @@ class Configurator(object): factory - A Python object (often a function or a class) or a - :term:`dotted Python name` which refers to the same object - that will generate a :app:`Pyramid` :term:`context` - object when this route matches. For example, - ``mypackage.models.MyFactoryClass``. If this argument is + A Python object (often a function or a class) or a :term:`dotted + Python name` which refers to the same object that will generate a + :app:`Pyramid` root resource object when this route matches. For + example, ``mypackage.resources.MyFactory``. If this argument is not specified, a default root factory will be used. traverse @@ -1679,7 +1678,7 @@ class Configurator(object): view_renderer This is either a single string term (e.g. ``json``) or a - string implying a path or :term:`resource specification` + string implying a path or :term:`asset specification` (e.g. ``templates/views.pt``). If the renderer value is a single term (does not contain a dot ``.``), the specified term will be used to look up a renderer implementation, and @@ -1873,7 +1872,7 @@ class Configurator(object): See :ref:`assets_chapter` for more information about asset overrides.""" if to_override == override_with: - raise ConfigurationError('You cannot override a resource with ' + raise ConfigurationError('You cannot override an asset with ' 'itself') package = to_override @@ -2098,7 +2097,7 @@ class Configurator(object): """ Add one or more :term:`translation directory` paths to the current configuration state. The ``specs`` argument is a sequence that may contain absolute directory paths - (e.g. ``/usr/share/locale``) or :term:`resource specification` + (e.g. ``/usr/share/locale``) or :term:`asset specification` names naming a directory path (e.g. ``some.package:locale``) or a combination of the two. @@ -2147,7 +2146,7 @@ class Configurator(object): @action_method def add_static_view(self, name, path, **kw): - """ Add a view used to render static resources such as images + """ Add a view used to render static assets such as images and CSS files. The ``name`` argument is a string representing :term:`view @@ -2156,40 +2155,39 @@ class Configurator(object): The ``path`` argument is the path on disk where the static files reside. This can be an absolute path, a - package-relative path, or a :term:`resource specification`. + package-relative path, or a :term:`asset specification`. The ``cache_max_age`` keyword argument is input to set the - ``Expires`` and ``Cache-Control`` headers for static resources + ``Expires`` and ``Cache-Control`` headers for static assets served. Note that this argument has no effect when the ``name`` is a *url prefix*. By default, this argument is ``None``, meaning that no particular Expires or Cache-Control headers are set in the response. The ``permission`` keyword argument is used to specify the - :term:`permission` required by a user to execute the static - view. By default, it is the string - ``__no_permission_required__``. The - ``__no_permission_required__`` string is a special sentinel - which indicates that, even if a :term:`default permission` - exists for the current application, the static view should be - renderered to completely anonymous users. This default value - is permissive because, in most web apps, static resources - seldom need protection from viewing. + :term:`permission` required by a user to execute the static view. By + default, it is the string ``__no_permission_required__``. The + ``__no_permission_required__`` string is a special sentinel which + indicates that, even if a :term:`default permission` exists for the + current application, the static view should be renderered to + completely anonymous users. This default value is permissive + because, in most web apps, static assets seldom need protection from + viewing. *Usage* The ``add_static_view`` function is typically used in conjunction with the :func:`pyramid.url.static_url` function. ``add_static_view`` adds a view which renders a - static resource when some URL is visited; + static asset when some URL is visited; :func:`pyramid.url.static_url` generates a URL to that - resource. + asset. The ``name`` argument to ``add_static_view`` is usually a :term:`view name`. When this is the case, the :func:`pyramid.url.static_url` API will generate a URL which points to a Pyramid view, which will serve up a set of - resources that live in the package itself. For example: + assets that live in the package itself. For example: .. code-block:: python @@ -2212,7 +2210,7 @@ class Configurator(object): be served. ``add_static_view`` can alternately be used with a ``name`` - argument which is a *URL*, causing static resources to be + argument which is a *URL*, causing static assets to be served from an external webserver. This happens when the ``name`` argument is a URL (detected as any string with a slash in it). In this mode, the ``name`` is used as the URL @@ -2241,7 +2239,7 @@ class Configurator(object): listening on ``example.com`` must be itself configured to respond properly to such a request. - See :ref:`static_resources_section` for more information. + See :ref:`static_assets_section` for more information. """ spec = self._make_spec(path) info = self.registry.queryUtility(IStaticURLInfo) @@ -2345,7 +2343,7 @@ class Configurator(object): def testing_add_renderer(self, path, renderer=None): """Unit/integration testing helper: register a renderer at ``path`` (usually a relative filename ala ``templates/foo.pt`` - or a resource specification) and return the renderer object. + or an asset specification) and return the renderer object. If the ``renderer`` argument is None, a 'dummy' renderer will be used. This function is useful when testing code that calls the :func:`pyramid.renderers.render` function or @@ -2513,7 +2511,7 @@ def _make_predicates(xhr=None, request_method=None, path_info=None, if traverse is not None: # ``traverse`` can only be used as a *route* "predicate"; it # adds 'traverse' to the matchdict if it's specified in the - # routing args. This causes the ModelGraphTraverser to use + # routing args. This causes the ResourceTreeTraverser to use # the resolved traverse pattern as the traversal path. from pyramid.urldispatch import _compile_route _, tgenerate = _compile_route(traverse) diff --git a/pyramid/interfaces.py b/pyramid/interfaces.py index 94affd2bb..d9b06abae 100644 --- a/pyramid/interfaces.py +++ b/pyramid/interfaces.py @@ -163,7 +163,7 @@ class IAuthorizationPolicy(Interface): """ Return a set of principal identifiers allowed by the permission """ class IStaticURLInfo(Interface): - """ A policy for generating URLs to static resources """ + """ A policy for generating URLs to static assets """ def add(name, spec, **extra): """ Add a new static info registration """ diff --git a/pyramid/location.py b/pyramid/location.py index 7472129d2..1df2ae143 100644 --- a/pyramid/location.py +++ b/pyramid/location.py @@ -12,29 +12,29 @@ # ############################################################################## -def inside(model1, model2): - """Is ``model1`` 'inside' ``model2``? Return ``True`` if so, else +def inside(resource1, resource2): + """Is ``resource1`` 'inside' ``resource2``? Return ``True`` if so, else ``False``. - ``model1`` is 'inside' ``model2`` if ``model2`` is a - :term:`lineage` ancestor of ``model1``. It is a lineage ancestor + ``resource1`` is 'inside' ``resource2`` if ``resource2`` is a + :term:`lineage` ancestor of ``resource1``. It is a lineage ancestor if its parent (or one of its parent's parents, etc.) is an ancestor. """ - while model1 is not None: - if model1 is model2: + while resource1 is not None: + if resource1 is resource2: return True - model1 = model1.__parent__ + resource1 = resource1.__parent__ return False -def lineage(model): +def lineage(resource): """ Return a generator representing the :term:`lineage` of the - :term:`model` object implied by the ``model`` argument. The - generator first returns ``model`` unconditionally. Then, if - ``model`` supplies a ``__parent__`` attribute, return the object - represented by ``model.__parent__``. If *that* object has a + :term:`resource` object implied by the ``resource`` argument. The + generator first returns ``resource`` unconditionally. Then, if + ``resource`` supplies a ``__parent__`` attribute, return the object + represented by ``resource.__parent__``. If *that* object has a ``__parent__`` attribute, return that object's parent, and so on, until the object being inspected either has no ``__parent__`` attribute or which has a ``__parent__`` attribute of ``None``. @@ -50,8 +50,8 @@ def lineage(model): list(lineage(thing2)) [ <Thing object at thing2>, <Thing object at thing1> ] """ - while model is not None: - yield model + while resource is not None: + yield resource # The common case is that the AttributeError exception below # is exceptional as long as the developer is a "good citizen" # who has a root object with a __parent__ of None. Using an @@ -60,7 +60,7 @@ def lineage(model): # called in any non-trivial application over and over again to # generate URLs and paths. try: - model = model.__parent__ + resource = resource.__parent__ except AttributeError: - model = None + resource = None diff --git a/pyramid/request.py b/pyramid/request.py index 4339f9ae3..a2dafc5e0 100644 --- a/pyramid/request.py +++ b/pyramid/request.py @@ -217,7 +217,7 @@ class Request(WebobRequest): Is completely equivalent to calling :func:`pyramid.url.resource_url` like this:: - from pyramid.url import model_url + from pyramid.url import resource_url resource_url(resource, request) .. note:: For backwards compatibility purposes, this method can also @@ -228,11 +228,12 @@ class Request(WebobRequest): model_url = resource_url # b/w compat forever def static_url(self, path, **kw): - """ Generates a fully qualified URL for a static :term:`resource`. - The resource must live within a location defined via the + """ + Generates a fully qualified URL for a static :term:`asset`. The + asset must live within a location defined via the :meth:`pyramid.config.Configurator.add_static_view` - :term:`configuration declaration` or the ``<static>`` ZCML - directive (see :ref:`static_resources_section`). + :term:`configuration declaration` or the ``<static>`` ZCML directive + (see :ref:`static_assets_section`). This is a convenience method. The result of calling :meth:`pyramid.request.Request.static_url` is the same as calling diff --git a/pyramid/router.py b/pyramid/router.py index 1b22a6a05..b665eeee2 100644 --- a/pyramid/router.py +++ b/pyramid/router.py @@ -22,7 +22,7 @@ from pyramid.exceptions import NotFound from pyramid.request import Request from pyramid.threadlocal import manager from pyramid.traversal import DefaultRootFactory -from pyramid.traversal import ModelGraphTraverser +from pyramid.traversal import ResourceTreeTraverser from pyramid.config import Configurator # b/c @@ -127,7 +127,7 @@ class Router(object): # find a context traverser = adapters.queryAdapter(root, ITraverser) if traverser is None: - traverser = ModelGraphTraverser(root) + traverser = ResourceTreeTraverser(root) tdict = traverser(request) context, view_name, subpath, traversed, vroot, vroot_path =( tdict['context'], tdict['view_name'], tdict['subpath'], @@ -239,13 +239,13 @@ def make_app(root_factory, package=None, filename='configure.zcml', ``filename`` passed or the value in the ``options`` dictionary named ``configure_zcml`` must be a) absolute pathname to a :term:`ZCML` file that represents the application's configuration - *or* b) a :term:`resource specification` to a :term:`ZCML` file in + *or* b) a :term:`asset specification` to a :term:`ZCML` file in the form ``dotted.package.name:relative/file/path.zcml``. ``filename`` is the filesystem path to a ZCML file (optionally relative to the package path) that should be parsed to create the application registry. It defaults to ``configure.zcml``. It can - also be a ;term:`resource specification` in the form + also be a ;term:`asset specification` in the form ``dotted_package_name:relative/file/path.zcml``. Note that if any value for ``configure_zcml`` is passed within the ``settings`` dictionary, the value passed as ``filename`` will be ignored, diff --git a/pyramid/security.py b/pyramid/security.py index 844cc05c8..723e87a87 100644 --- a/pyramid/security.py +++ b/pyramid/security.py @@ -26,7 +26,7 @@ DENY_ALL = (Deny, Everyone, ALL_PERMISSIONS) def has_permission(permission, context, request): """ Provided a permission (a string or unicode object), a context - (a :term:`model` instance) and a request object, return an + (a :term:`resource` instance) and a request object, return an instance of :data:`pyramid.security.Allowed` if the permission is granted in this context to the user implied by the request. Return an instance of :mod:`pyramid.security.Denied` @@ -81,7 +81,7 @@ def effective_principals(request): return policy.effective_principals(request) def principals_allowed_by_permission(context, permission): - """ Provided a ``context`` (a model object), and a ``permission`` + """ Provided a ``context`` (a resource object), and a ``permission`` (a string or unicode object), if a :term:`authorization policy` is in effect, return a sequence of :term:`principal` ids that possess the permission in the ``context``. If no authorization policy is diff --git a/pyramid/settings.py b/pyramid/settings.py index d3354979a..395694fa0 100644 --- a/pyramid/settings.py +++ b/pyramid/settings.py @@ -44,7 +44,7 @@ class Settings(dict): config_reload_assets)) reload_resources = asbool(eget('BFG_RELOAD_RESOURCES', config_reload_resources)) - # reload_resources is an older alias for reload_resources + # reload_resources is an older alias for reload_assets eff_reload_assets = reload_assets or reload_resources configure_zcml = self.get('configure_zcml', '') eff_configure_zcml = eget('BFG_CONFIGURE_ZCML', configure_zcml) diff --git a/pyramid/static.py b/pyramid/static.py index e2f400ef6..5e4faf6fe 100644 --- a/pyramid/static.py +++ b/pyramid/static.py @@ -108,7 +108,7 @@ class StaticURLInfo(object): def add(self, name, spec, **extra): # This feature only allows for the serving of a directory and - # the files contained within, not of a single resource; + # the files contained within, not of a single asset; # appending a slash here if the spec doesn't have one is # required for proper prefix matching done in ``generate`` # (``subpath = path[len(spec):]``). @@ -162,7 +162,7 @@ class static_view(object): path into a response. You may pass an absolute or relative filesystem path or a - :term:`resource specification` representing the directory + :term:`asset specification` representing the directory containing static files as the ``root_dir`` argument to this class' constructor. @@ -179,13 +179,13 @@ class static_view(object): five minutes). .. note:: If the ``root_dir`` is relative to a :term:`package`, or - is a :term:`resource specification` the :app:`Pyramid` - ``resource`` ZCML directive or + is a :term:`asset specification` the :app:`Pyramid` + ``asset`` ZCML directive or :class:`pyramid.config.Configurator` method can be - used to override resources within the named ``root_dir`` + used to override assets within the named ``root_dir`` package-relative directory. However, if the ``root_dir`` is - absolute, the ``resource`` directive will not be able to - override the resources it contains. """ + absolute, configuration will not be able to + override the assets it contains. """ def __init__(self, root_dir, cache_max_age=3600, package_name=None): # package_name is for bw compat; it is preferred to pass in a diff --git a/pyramid/testing.py b/pyramid/testing.py index 8d48bfdf4..4bcda906b 100644 --- a/pyramid/testing.py +++ b/pyramid/testing.py @@ -62,29 +62,34 @@ def registerDummySecurityPolicy(userid=None, groupids=(), permissive=True): config.commit() return result -def registerModels(models): - """ Registers a dictionary of :term:`model` objects that can be - resolved via the :func:`pyramid.traversal.find_model` API. +def registerResources(resources): + """ Registers a dictionary of :term:`resource` objects that can be + resolved via the :func:`pyramid.traversal.find_resource` API. - The :func:`pyramid.traversal.find_model` API is called with a + The :func:`pyramid.traversal.find_resource` API is called with a path as one of its arguments. If the dictionary you register when calling this method contains that path as a string key (e.g. ``/foo/bar`` or ``foo/bar``), the corresponding value will - be returned to ``find_model`` (and thus to your code) when - :func:`pyramid.traversal.find_model` is called with an + be returned to ``find_resource`` (and thus to your code) when + :func:`pyramid.traversal.find_resource` is called with an equivalent path string or tuple. .. warning:: This API is deprecated as of :app:`Pyramid` 1.0. Instead use the - :meth:`pyramid.config.Configurator.testing_models` + :meth:`pyramid.config.Configurator.testing_resources` method in your unit and integration tests. + + .. note:: For ancient backward compatibility purposes, this API can also + be accessed as :func:`pyramid.testing.registerModels`. """ registry = get_current_registry() config = Configurator(registry=registry) - result = config.testing_models(models) + result = config.testing_resources(resources) config.commit() return result +registerModels = registerResources + def registerEventListener(event_iface=None): """ Registers an :term:`event` listener (aka :term:`subscriber`) listening for events of the type ``event_iface``. This method @@ -412,19 +417,19 @@ class DummyTemplateRenderer(object): v, k, myval)) return True -class DummyModel: - """ A dummy :app:`Pyramid` :term:`model` object.""" +class DummyResource: + """ A dummy :app:`Pyramid` :term:`resource` object.""" def __init__(self, __name__=None, __parent__=None, __provides__=None, **kw): - """ The model's ``__name__`` attribute will be set to the - value of the ``__name__`` argument, and the model's + """ The resource's ``__name__`` attribute will be set to the + value of the ``__name__`` argument, and the resource's ``__parent__`` attribute will be set to the value of the ``__parent__`` argument. If ``__provides__`` is specified, it should be an interface object or tuple of interface objects - that will be attached to the resulting model via + that will be attached to the resulting resource via :func:`zope.interface.alsoProvides`. Any extra keywords passed in the ``kw`` argumnent will be set as direct attributes of - the model object.""" + the resource object.""" self.__name__ = __name__ self.__parent__ = __parent__ if __provides__ is not None: @@ -436,9 +441,9 @@ class DummyModel: def __setitem__(self, name, val): """ When the ``__setitem__`` method is called, the object passed in as ``val`` will be decorated with a ``__parent__`` - attribute pointing at the dummy model and a ``__name__`` + attribute pointing at the dummy resource and a ``__name__`` attribute that is the value of ``name``. The value will then - be returned when dummy model's ``__getitem__`` is called with + be returned when dummy resource's ``__getitem__`` is called with the name ``name```.""" val.__name__ = name val.__parent__ = self @@ -479,12 +484,12 @@ class DummyModel: return name in self.subs def clone(self, __name__=_marker, __parent__=_marker, **kw): - """ Create a clone of the model object. If ``__name__`` or + """ Create a clone of the resource object. If ``__name__`` or ``__parent__`` arguments are passed, use these values to override the existing ``__name__`` or ``__parent__`` of the - model. If any extra keyword args are passed in via the ``kw`` + resource. If any extra keyword args are passed in via the ``kw`` argument, use these keywords to add to or override existing - model keywords (attributes).""" + resource keywords (attributes).""" oldkw = self.kw.copy() oldkw.update(kw) inst = self.__class__(self.__name__, self.__parent__, **oldkw) @@ -495,6 +500,8 @@ class DummyModel: inst.__parent__ = __parent__ return inst +DummyModel = DummyResource # b/w compat (forever) + class DummyRequest(object): """ A dummy request object (imitates a :term:`request` object). @@ -509,6 +516,9 @@ class DummyRequest(object): Extra keyword arguments are assigned as attributes of the request itself. + + .. note:: For backwards compatibility purposes, this class can also be + imported as :class:`pyramid.testing.DummyModel`. """ implements(IRequest) method = 'GET' @@ -571,7 +581,7 @@ def setUp(registry=None, request=None, hook_zca=True, autocommit=True): which directly or indirectly uses: - any of the ``register*`` functions in :mod:`pyramid.testing` - (such as :func:`pyramid.testing.registerModels`) + (such as :func:`pyramid.testing.registerResources`) - any method of the :class:`pyramid.config.Configurator` object returned by this function. diff --git a/pyramid/tests/test_authorization.py b/pyramid/tests/test_authorization.py index e44eb86c5..c4b2fb142 100644 --- a/pyramid/tests/test_authorization.py +++ b/pyramid/tests/test_authorization.py @@ -117,7 +117,7 @@ class TestACLAuthorizationPolicy(unittest.TestCase): self.assertEqual(result.ace, '<default deny>') self.assertEqual( result.acl, - '<No ACL found on any object in model lineage>') + '<No ACL found on any object in resource lineage>') def test_principals_allowed_by_permission_direct(self): from pyramid.security import Allow diff --git a/pyramid/tests/test_testing.py b/pyramid/tests/test_testing.py index 40513be81..ec6fdac5f 100644 --- a/pyramid/tests/test_testing.py +++ b/pyramid/tests/test_testing.py @@ -33,13 +33,13 @@ class Test_registerDummySecurityPolicy(TestBase): self.assertEqual(ut.groupids, ('group1', 'group2')) self.assertEqual(ut.permissive, False) -class Test_registerModels(TestBase): - def test_registerModels(self): +class Test_registerResources(TestBase): + def test_it(self): ob1 = object() ob2 = object() - models = {'/ob1':ob1, '/ob2':ob2} + resources = {'/ob1':ob1, '/ob2':ob2} from pyramid import testing - testing.registerModels(models) + testing.registerResources(resources) from pyramid.interfaces import ITraverser adapter = self.registry.getAdapter(None, ITraverser) result = adapter({'PATH_INFO':'/ob1'}) @@ -57,8 +57,8 @@ class Test_registerModels(TestBase): self.assertEqual(result['virtual_root'], ob2) self.assertEqual(result['virtual_root_path'], ()) self.assertRaises(KeyError, adapter, {'PATH_INFO':'/ob3'}) - from pyramid.traversal import find_model - self.assertEqual(find_model(None, '/ob1'), ob1) + from pyramid.traversal import find_resource + self.assertEqual(find_resource(None, '/ob1'), ob1) class Test_registerTemplateRenderer(TestBase): def test_registerTemplateRenderer(self): @@ -331,10 +331,10 @@ class TestDummySecurityPolicy(unittest.TestCase): -class TestDummyModel(unittest.TestCase): +class TestDummyResource(unittest.TestCase): def _getTargetClass(self): - from pyramid.testing import DummyModel - return DummyModel + from pyramid.testing import DummyResource + return DummyResource def _makeOne(self, name=None, parent=None, **kw): klass = self._getTargetClass() @@ -344,26 +344,26 @@ class TestDummyModel(unittest.TestCase): class Dummy: pass dummy = Dummy() - model = self._makeOne() - model['abc'] = dummy + resource = self._makeOne() + resource['abc'] = dummy self.assertEqual(dummy.__name__, 'abc') - self.assertEqual(dummy.__parent__, model) - self.assertEqual(model['abc'], dummy) - self.assertEqual(model.get('abc'), dummy) - self.assertRaises(KeyError, model.__getitem__, 'none') - self.failUnless('abc' in model) - del model['abc'] - self.failIf('abc' in model) - self.assertEqual(model.get('abc', 'foo'), 'foo') - self.assertEqual(model.get('abc'), None) + self.assertEqual(dummy.__parent__, resource) + self.assertEqual(resource['abc'], dummy) + self.assertEqual(resource.get('abc'), dummy) + self.assertRaises(KeyError, resource.__getitem__, 'none') + self.failUnless('abc' in resource) + del resource['abc'] + self.failIf('abc' in resource) + self.assertEqual(resource.get('abc', 'foo'), 'foo') + self.assertEqual(resource.get('abc'), None) def test_extra_params(self): - model = self._makeOne(foo=1) - self.assertEqual(model.foo, 1) + resource = self._makeOne(foo=1) + self.assertEqual(resource.foo, 1) def test_clone(self): - model = self._makeOne('name', 'parent', foo=1, bar=2) - clone = model.clone('name2', 'parent2', bar=1) + resource = self._makeOne('name', 'parent', foo=1, bar=2) + clone = resource.clone('name2', 'parent2', bar=1) self.assertEqual(clone.bar, 1) self.assertEqual(clone.__name__, 'name2') self.assertEqual(clone.__parent__, 'parent2') @@ -372,21 +372,21 @@ class TestDummyModel(unittest.TestCase): def test_keys_items_values_len(self): class Dummy: pass - model = self._makeOne() - model['abc'] = Dummy() - model['def'] = Dummy() - self.assertEqual(model.values(), model.subs.values()) - self.assertEqual(model.items(), model.subs.items()) - self.assertEqual(model.keys(), model.subs.keys()) - self.assertEqual(len(model), 2) + resource = self._makeOne() + resource['abc'] = Dummy() + resource['def'] = Dummy() + self.assertEqual(resource.values(), resource.subs.values()) + self.assertEqual(resource.items(), resource.subs.items()) + self.assertEqual(resource.keys(), resource.subs.keys()) + self.assertEqual(len(resource), 2) def test_nonzero(self): - model = self._makeOne() - self.assertEqual(model.__nonzero__(), True) + resource = self._makeOne() + self.assertEqual(resource.__nonzero__(), True) def test_ctor_with__provides__(self): - model = self._makeOne(__provides__=IDummy) - self.failUnless(IDummy.providedBy(model)) + resource = self._makeOne(__provides__=IDummy) + self.failUnless(IDummy.providedBy(resource)) class TestDummyRequest(unittest.TestCase): def _getTargetClass(self): diff --git a/pyramid/traversal.py b/pyramid/traversal.py index 6a9e20ed5..086823695 100644 --- a/pyramid/traversal.py +++ b/pyramid/traversal.py @@ -74,7 +74,7 @@ def find_resource(resource, path): resolved by ``find_resource``. .. note:: For backwards compatibility purposes, this function can also - be imported as ``find_model``. + be imported as :func:`pyramid.traversal.find_model`. """ D = traverse(resource, path) view_name = D['view_name'] diff --git a/pyramid/url.py b/pyramid/url.py index 109ee7ecf..6ae0ce8c4 100644 --- a/pyramid/url.py +++ b/pyramid/url.py @@ -304,11 +304,11 @@ model_url = resource_url # b/w compat (forever) def static_url(path, request, **kw): """ - Generates a fully qualified URL for a static :term:`resource`. - The resource must live within a location defined via the + Generates a fully qualified URL for a static :term:`asset`. + The asset must live within a location defined via the :meth:`pyramid.config.Configurator.add_static_view` :term:`configuration declaration` or the ``<static>`` ZCML - directive (see :ref:`static_resources_section`). + directive (see :ref:`static_assets_section`). .. note:: Calling :meth:`pyramid.Request.static_url` can be used to achieve the same result as :func:`pyramid.url.static_url`. @@ -322,7 +322,7 @@ def static_url(path, request, **kw): The ``path`` argument points at a file or directory on disk which a URL should be generated for. The ``path`` may be either a - relative path (e.g. ``static/foo.css``) or a :term:`resource + relative path (e.g. ``static/foo.css``) or a :term:`asset specification` (e.g. ``mypackage:static/foo.css``). A ``path`` may not be an absolute filesystem path (a :exc:`ValueError` will be raised if this function is supplied with an absolute path). @@ -333,7 +333,7 @@ def static_url(path, request, **kw): the :func:`pyramid.url.route_url` ``**kw`` argument. See the documentation for that function to understand the arguments which you can provide to it. However, typically, you don't need to pass - anything as ``*kw`` when generating a static resource URL. + anything as ``*kw`` when generating a static asset URL. This function raises a :exc:`ValueError` if a static view definition cannot be found which matches the path specification. @@ -341,7 +341,7 @@ def static_url(path, request, **kw): """ if os.path.isabs(path): raise ValueError('Absolute paths cannot be used to generate static ' - 'urls (use a package-relative path or a resource ' + 'urls (use a package-relative path or an asset ' 'specification).') if not ':' in path: # if it's not a package:relative/name and it's not an diff --git a/pyramid/view.py b/pyramid/view.py index d18d0dba3..cd313e5a8 100644 --- a/pyramid/view.py +++ b/pyramid/view.py @@ -147,9 +147,9 @@ class view_config(object): For example, this code in a module ``views.py``:: - from models import MyModel + from resources import MyResource - @view_config(name='my_view', context=MyModel, permission='read', + @view_config(name='my_view', context=MyResource, permission='read', route_name='site1') def my_view(context, request): return 'OK' @@ -158,14 +158,14 @@ class view_config(object): :meth:`pyramid.config.Configurator.add_view` method:: import views - import models - config.add_view(views.my_view, context=models.MyModel, name='my_view', + from resources import MyResource + config.add_view(views.my_view, context=MyResource, name='my_view', permission='read', 'route_name='site1') Or might replace the following ZCML ``view`` declaration:: <view - for='.models.MyModel' + for='.resources.MyResource' view='.views.my_view' name='my_view' permission='read' |
