/usr/share/pyshared/zc/resourcelibrary/zcml.py is in python-zc.resourcelibrary 1.3.4-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | ##############################################################################
#
# Copyright (c) 2006 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
import os.path
from zope.browserresource.directory import DirectoryResourceFactory
from zope.browserresource.metadirectives import IBasicResourceInformation
from zope.browserresource.metaconfigure import allowed_names
from zope.component import getSiteManager
from zope.configuration.exceptions import ConfigurationError
from zope.interface import Interface
from zope.publisher.interfaces.browser import IBrowserRequest
from zope.publisher.interfaces.browser import IDefaultBrowserLayer
from zope.security.checker import CheckerPublic, NamesChecker
import zope.configuration.fields
from zc.resourcelibrary.resourcelibrary import LibraryInfo, library_info
class IResourceLibraryDirective(IBasicResourceInformation):
"""
Defines a resource library
"""
name = zope.schema.TextLine(
title=u"The name of the resource library",
description=u"""\
This is the name used to disambiguate resource libraries. No two
libraries can be active with the same name.""",
required=True,
)
require = zope.configuration.fields.Tokens(
title=u"Require",
description=u"The resource libraries on which this library depends.",
required=False,
value_type=zope.schema.Text(),
)
class IDirectoryDirective(Interface):
"""
Identifies a directory to be included in a resource library
"""
source = zope.configuration.fields.Path(
title=u"Source",
description=u"The directory containing the files to add.",
required=True,
)
include = zope.configuration.fields.Tokens(
title=u"Include",
description=u"The files which should be included in HTML pages which "
u"reference this resource library.",
required=False,
value_type=zope.schema.Text(),
)
factory = zope.configuration.fields.GlobalObject(
title=u"Factory",
description=u"Alternate directory-resource factory",
required=False,
)
def handler(name, dependencies, required, provided, adapter_name, factory, info=''):
if dependencies:
for dep in dependencies:
if dep not in library_info:
raise ConfigurationError(
'Resource library "%s" has unsatisfied dependency on "%s".'
% (name, dep))
getSiteManager().registerAdapter(
factory, required, provided, adapter_name, info)
INCLUDABLE_EXTENSIONS = ('.js', '.css', '.kss')
class ResourceLibrary(object):
def __init__(self, _context, name, require=(),
layer=IDefaultBrowserLayer, permission='zope.Public'):
self.name = name
self.layer = layer
if permission == 'zope.Public':
permission = CheckerPublic
self.checker = NamesChecker(allowed_names, permission)
# make note of the library in a global registry
self.old_library_info = library_info.get(name)
library_info[name] = LibraryInfo()
library_info[name].required.extend(require)
def directory(self, _context, source, include=(), factory=None):
if not os.path.isdir(source):
raise ConfigurationError("Directory %r does not exist" % source)
for file_name in include:
ext = os.path.splitext(file_name)[1]
if ext not in INCLUDABLE_EXTENSIONS:
raise ConfigurationError(
'Resource library doesn\'t know how to include this '
'file: "%s".' % file_name)
# remember which files should be included in the HTML when this library
# is referenced
library_info[self.name].included.extend(include)
if factory is None:
factory = DirectoryResourceFactory
factory = factory(source, self.checker, self.name)
_context.action(
discriminator = ('resource', self.name, IBrowserRequest, self.layer),
callable = handler,
args = (self.name, library_info[self.name].required, (self.layer,),
Interface, self.name, factory, _context.info),
)
def __call__(self):
if self.old_library_info is None:
return
curr_li = library_info[self.name]
if self.old_library_info.included != curr_li.included or \
self.old_library_info.required != curr_li.required:
raise NotImplementedError(
"Can't cope with 2 different registrations of the same "
"library: %s (%s, %s) (%s, %s)" % (self.name,
self.old_library_info.required,
self.old_library_info.included,
curr_li.required,
curr_li.included))
|