/
__init__.py
57 lines (55 loc) · 2.18 KB
/
__init__.py
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
# KidKit
# Webware for Python
# See Docs/index.html
def InstallInWebKit(appServer):
app = appServer.application()
from WebKit.PlugIn import PlugInError
try:
try:
from KidKit.Properties import requiredSoftware
except ImportError:
raise PlugInError('Cannot determine required software.')
for soft in requiredSoftware:
if soft['name'] == 'kid':
requiredKidVersion = soft['version']
break
else:
raise PlugInError('Cannot determine required Kid version.')
try:
import kid
except ImportError:
raise PlugInError(
'Cannot import Kid. This needs to be installed to use KidKit.')
try:
kidVersion = tuple(map(lambda s:
int('0' + ''.join(filter(lambda c: c.isdigit(), s))),
kid.__version__.split('.', 3)[:3]))
except ImportError:
raise PlugInError('Cannot determine Kid version.')
if kidVersion < requiredKidVersion:
raise PlugInError(
'KidKit needs at least Kid version %s (installed is %s).'
% ('.'.join(map(str, requiredKidVersion)),
'.'.join(map(str, kidVersion))))
try:
from KidServletFactory import KidServletFactory
app.addServletFactory(KidServletFactory(app))
except Exception:
from traceback import print_exc
print_exc()
raise PlugInError('Cannot install Kid servlet factory.')
except PlugInError as e:
print e
print "KidKit will not be loaded, '.kid' extension will be ignored."
# We need to disable the '.kid' extension because otherwise the kid
# templates would be delivered as ordinary files (security problem).
e = app.setting('ExtensionsToIgnore', [])
if '.kid' not in e:
e.append('.kid')
app.setSetting('ExtensionsToIgnore', e)
e = app.setting('FilesToHide', [])
if '*.kid' not in e:
e.append('*.kid')
app.setSetting('FilesToHide', e)
from WebKit.URLParser import initParser
initParser(app)