File: __init__.py

package info (click to toggle)
zope-replacesupport 1.0.2-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 168 kB
  • ctags: 155
  • sloc: python: 743; makefile: 38; sh: 25
file content (44 lines) | stat: -rw-r--r-- 1,311 bytes parent folder | download
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
# ReplaceSupport 1.0.2
# (c) 2000-2004, Stefan H. Holek, stefan@epy.co.at
# http://zope.org/Members/shh/ReplaceSupport
# License: ZPL
# Zope: 2.3-2.7

__doc__ = 'ReplaceHandler registry'
__version__ = '0.2.0'

class HandlerRegistry:
        '''Handler registry'''

        def __init__( self ):
                self._handlers = {}
        
        def getHandler( self, metatype ):
                try:    return self._handlers[metatype]
                except: return None

        def registerHandler( self, handler ):
                self._handlers[handler.getMetaType()] = handler

        def getHandlerMetaTypes( self ):
                keys = self._handlers.keys()
                keys.sort()
                return keys

reg = HandlerRegistry()

from Globals import package_home
import os

handlers = os.listdir( package_home(globals()) )
handlers = filter( lambda x: x[-3:] == '.py' and x[:1] != '_', handlers )
handlers = map( lambda x: x[:-3], handlers )

for module in handlers:
        exec 'from %s import %s' % (module, '__handler_class_name__')
        exec 'from %s import %s' % (module, __handler_class_name__)
        reg.registerHandler( eval('%s()' % __handler_class_name__) )

from Products.ReplaceSupport.ReplaceSupport import ReplaceSupport
ReplaceSupport._ReplaceHandlerRegistry = reg