Directories of Resources: zope.browserresource.directory

Resource Directory

A ‘resource directory’ is an on-disk directory which is registered as a resource using the <resourceDirectory> ZCML directive. The directory is treated as a source for individual resources; it can be traversed to retrieve resources represented by contained files, which can in turn be treated as resources. The contained files have __name__ values which include a ‘/’ separating the __name__ of the resource directory from the name of the file within the directory.

class zope.browserresource.directory.DirectoryResource(context, request)[source]

Bases: zope.publisher.browser.BrowserView, zope.browserresource.resource.Resource

A resource representing an entire directory.

It is traversable to the items contained within the directory. See get.

default_factory

alias of zope.browserresource.file.FileResourceFactory

directory_factory

The resource factory to use for directories.

alias of DirectoryResourceFactory

forbidden_names = ('.svn', '.git')

A sequence of name patterns usable with fnmatch.fnmatch. Traversing to files that match these names will not produce resources.

publishTraverse(request, name)[source]

Uses get to traverse to the name.

See also

zope.publisher.interfaces.browser.IBrowserPublisher.publishTraverse()

browserDefault(request)[source]

Returns an empty callable and tuple.

get(name, default=<object object>)[source]

Locate name on the filesystem and return a IResource for it.

If the name cannot be found and no default is given, then raise NotFound.

If the name matches one of the forbidden patterns then returns the default (if given) or raise NotFound (when not given).

When the name refers to a file, we query for a IResourceFactoryFactory utility named for the file’s extension (e.g., css) and use it to produce a resource. If no such utility can be found, we use our default.

When the name refers to a directory, we use our directory factory.