vendor/CMF/1.6.3/CMFCore

view SkinsContainer.py @ 2:4c712d7bd1d7

Added tag 1.6.3 for changeset 1babb9d61518
author Georges Racinet on purity.racinet.fr <georges@racinet.fr>
date Fri, 09 Sep 2011 12:44:00 +0200
parents
children
line source
1 ##############################################################################
2 #
3 # Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
4 #
5 # This software is subject to the provisions of the Zope Public License,
6 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
10 # FOR A PARTICULAR PURPOSE.
11 #
12 ##############################################################################
13 """ Base class for objects that supply skins.
15 $Id$
16 """
18 from AccessControl import ClassSecurityInfo
19 from Acquisition import aq_base
20 from Globals import InitializeClass
22 from exceptions import SkinPathError
23 from interfaces.portal_skins import SkinsContainer as ISkinsContainer
24 from permissions import AccessContentsInformation
27 class SkinsContainer:
29 __implements__ = ISkinsContainer
31 security = ClassSecurityInfo()
33 security.declareProtected(AccessContentsInformation, 'getSkinPath')
34 def getSkinPath(self, name):
35 """ Convert a skin name to a skin path.
36 """
37 raise NotImplementedError
39 security.declareProtected(AccessContentsInformation, 'getDefaultSkin')
40 def getDefaultSkin(self):
41 """ Get the default skin name.
42 """
43 raise NotImplementedError
45 security.declareProtected(AccessContentsInformation, 'getRequestVarname')
46 def getRequestVarname(self):
47 """ Get the variable name to look for in the REQUEST.
48 """
49 raise NotImplementedError
51 security.declarePrivate('getSkinByPath')
52 def getSkinByPath(self, path, raise_exc=0):
53 """ Get a skin at the given path.
54 """
55 baseself = aq_base(self)
56 skinob = None
57 parts = list( path.split(',') )
58 parts.reverse()
59 for part_path in parts:
60 partob = baseself
61 for name in part_path.strip().split('/'):
62 if name == '':
63 continue
64 if name[:1] == '_':
65 # Not allowed.
66 partob = None
67 if raise_exc:
68 raise SkinPathError('Underscores are not allowed')
69 break
70 # Allow acquisition tricks.
71 partob = getattr(partob, name, None)
72 if partob is None:
73 # Not found. Cancel the search.
74 if raise_exc:
75 raise SkinPathError('Name not found: %s' % part_path)
76 break
77 if partob is not None:
78 # Now partob has containment and context.
79 # Build the final skinob by creating an object
80 # that puts the former skinob in the context
81 # of the new skinob.
82 partob = aq_base(partob)
83 if skinob is None:
84 skinob = partob
85 else:
86 skinob = partob.__of__(skinob)
87 return skinob
89 security.declarePrivate('getSkinByName')
90 def getSkinByName(self, name):
91 """ Get the named skin.
92 """
93 path = self.getSkinPath(name)
94 if path is None:
95 return None
96 return self.getSkinByPath(path)
98 InitializeClass( SkinsContainer )