/usr/share/pyshared/nevow/jsutil.py is in python-nevow 0.10.0-4build1.
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 | # -*- test-case-name: nevow.test.test_consolejstest -*-
# Copyright (c) 2004-2007 Divmod.
# See LICENSE for details.
from twisted.python.procutils import which
from twisted.python.util import sibpath
import nevow
from nevow.athena import (LivePage, allJavascriptPackages, AthenaModule,
jsModuleDeclaration)
_TEST_BOOTSTRAP = LivePage.BOOTSTRAP_MODULES[:]
_TEST_BOOTSTRAP.insert(_TEST_BOOTSTRAP.index('Divmod.Runtime'),
'Divmod.MockBrowser')
_DUMMY_MODULE_NAME = 'ConsoleJSTest'
def getDependencies(fname, ignore=[],
bootstrap=_TEST_BOOTSTRAP,
packages=None):
"""
Get the javascript modules that the code in the file with name C{fname}
depends on, recursively
@param fname: javascript source file name
@type fname: C{str}
@param ignore: names of javascript modules to exclude from dependency list
@type ignore: sequence
@param bootstrap: names of javascript modules to always include, regardless
of explicit dependencies (defaults to L{LivePage}'s list of bootstrap
modules, plus the mock browser implementation.)
@type boostrap: sequence
@param packages: all javascript packages we know about. defaults to the
result of L{allJavascriptPackages}
@type packages: C{dict}
@return: modules included by javascript in file named C{fname}
@rtype: dependency-ordered list of L{AthenaModule} instances
"""
if packages is None:
packages = allJavascriptPackages()
# TODO if a module is ignored, we should ignore its dependencies
bootstrapModules = [AthenaModule.getOrCreate(m, packages)
for m in bootstrap if m not in ignore]
packages[_DUMMY_MODULE_NAME] = fname
module = AthenaModule(_DUMMY_MODULE_NAME, packages)
return (bootstrapModules +
[dep for dep in module.allDependencies()
if (dep.name not in bootstrap
and dep.name != _DUMMY_MODULE_NAME
and dep.name not in ignore)])
def findJavascriptInterpreter():
"""
Return a string path to a JavaScript interpreter if one can be found in
the executable path. If not, return None.
"""
for script in ['smjs', 'js']:
_jsInterps = which(script)
if _jsInterps:
return _jsInterps[0]
return None
def generateTestScript(fname, after={}, dependencies=None):
"""
Turn the contents of the Athena-style javascript test module in the file
named C{fname} into a plain javascript script. Recursively includes any
modules that are depended on, as well as the utility module
nevow/test/testsupport.js.
@param fname: javascript source file name
@type fname: C{str}
@param after: mapping of javascript module names to sequences of lines of
javascript source that should be injected into the output immediately
after the source of the named module is included
@type after: C{dict}
@param dependencies: the modules the script depends on. Defaults to the
result of L{getDependencies}
@type dependencies: dependency-ordered list of L{AthenaModule} instances
@return: converted javascript source text
@rtype: C{str}
"""
if dependencies is None:
dependencies = getDependencies(fname)
load = lambda fname: 'load(%r);' % (fname,)
initialized = {}
js = [load(sibpath(nevow.__file__, 'test/testsupport.js'))]
for m in dependencies:
segments = m.name.split('.')
if segments[-1] == '__init__':
segments = segments[:-1]
initname = '.'.join(segments)
if initname not in initialized:
initialized[initname] = 1
js.append(jsModuleDeclaration(initname))
js.append(load(m.mapping[m.name]))
if m.name in after:
js.extend(after[m.name])
js.append(file(fname).read())
return '\n'.join(js)
|