Mercurial > pydertron
annotate pydertron.py @ 15:f30bd92e2216
Added support for running test suite over http.
| author | Atul Varma <varmaa@toolness.com> |
|---|---|
| date | Thu, 10 Sep 2009 14:36:17 -0700 |
| parents | 16fe9c63aedb |
| children | 9426f9fa6dc0 |
| rev | line source |
|---|---|
| 0 | 1 import sys |
| 2 import threading | |
| 3 import traceback | |
| 4 import weakref | |
| 5 import types | |
|
7
2117265e4dfe
Fixed some threading issues.
Atul Varma <varmaa@toolness.com>
parents:
6
diff
changeset
|
6 import atexit |
| 0 | 7 |
| 8 import pydermonkey | |
| 9 | |
| 10 class ContextWatchdogThread(threading.Thread): | |
| 11 """ | |
| 12 Watches active JS contexts and triggers their operation callbacks | |
| 13 at a regular interval. | |
| 14 """ | |
| 15 | |
| 16 # Default interval, in seconds, that the operation callbacks are | |
| 17 # triggered at. | |
|
8
fb0b161542b1
Improved performance of watchdog thread.
Atul Varma <varmaa@toolness.com>
parents:
7
diff
changeset
|
18 DEFAULT_INTERVAL = 0.25 |
| 0 | 19 |
| 20 def __init__(self, interval=DEFAULT_INTERVAL): | |
| 21 threading.Thread.__init__(self) | |
| 22 self._lock = threading.Lock() | |
| 23 self._stop = threading.Event() | |
| 24 self._contexts = [] | |
| 25 self.interval = interval | |
| 26 | |
| 27 def add_context(self, cx): | |
| 28 self._lock.acquire() | |
| 29 try: | |
| 30 self._contexts.append(weakref.ref(cx)) | |
| 31 finally: | |
| 32 self._lock.release() | |
| 33 | |
| 34 def join(self): | |
| 35 self._stop.set() | |
| 36 threading.Thread.join(self) | |
| 37 | |
| 38 def run(self): | |
| 39 while not self._stop.isSet(): | |
| 40 new_list = [] | |
| 41 self._lock.acquire() | |
| 42 try: | |
| 43 for weakcx in self._contexts: | |
| 44 cx = weakcx() | |
| 45 if cx: | |
| 46 new_list.append(weakcx) | |
| 47 cx.trigger_operation_callback() | |
|
7
2117265e4dfe
Fixed some threading issues.
Atul Varma <varmaa@toolness.com>
parents:
6
diff
changeset
|
48 del cx |
| 0 | 49 self._contexts = new_list |
| 50 finally: | |
| 51 self._lock.release() | |
|
8
fb0b161542b1
Improved performance of watchdog thread.
Atul Varma <varmaa@toolness.com>
parents:
7
diff
changeset
|
52 self._stop.wait(self.interval) |
| 0 | 53 |
| 54 # Create a global watchdog. | |
| 55 watchdog = ContextWatchdogThread() | |
| 56 watchdog.start() | |
|
7
2117265e4dfe
Fixed some threading issues.
Atul Varma <varmaa@toolness.com>
parents:
6
diff
changeset
|
57 atexit.register(watchdog.join) |
| 0 | 58 |
| 59 class InternalError(BaseException): | |
| 60 """ | |
| 61 Represents an error in a JS-wrapped Python function that wasn't | |
| 62 expected to happen; because it's derived from BaseException, it | |
| 63 unrolls the whole JS/Python stack so that the error can be | |
| 64 reported to the outermost calling code. | |
| 65 """ | |
| 66 | |
| 67 def __init__(self): | |
| 68 BaseException.__init__(self) | |
| 69 self.exc_info = sys.exc_info() | |
| 70 | |
| 71 class SafeJsObjectWrapper(object): | |
| 72 """ | |
| 73 Securely wraps a JS object to behave like any normal Python object. | |
| 74 """ | |
| 75 | |
| 76 __slots__ = ['_jsobject', '_sandbox', '_this'] | |
| 77 | |
| 78 def __init__(self, sandbox, jsobject, this): | |
| 79 if not isinstance(jsobject, pydermonkey.Object): | |
| 80 raise TypeError("Cannot wrap '%s' object" % | |
| 81 type(jsobject).__name__) | |
| 82 object.__setattr__(self, '_sandbox', sandbox) | |
| 83 object.__setattr__(self, '_jsobject', jsobject) | |
| 84 object.__setattr__(self, '_this', this) | |
| 85 | |
| 86 @property | |
| 87 def wrapped_jsobject(self): | |
| 88 return self._jsobject | |
| 89 | |
| 90 def _wrap_to_python(self, jsvalue): | |
| 91 return self._sandbox.wrap_jsobject(jsvalue, self._jsobject) | |
| 92 | |
| 93 def _wrap_to_js(self, value): | |
| 94 return self._sandbox.wrap_pyobject(value) | |
| 95 | |
| 96 def __eq__(self, other): | |
| 97 if isinstance(other, SafeJsObjectWrapper): | |
| 98 return self._jsobject == other._jsobject | |
| 99 else: | |
| 100 return False | |
| 101 | |
| 102 def __str__(self): | |
| 103 return self.toString() | |
| 104 | |
| 105 def __unicode__(self): | |
| 106 return self.toString() | |
| 107 | |
| 108 def __setitem__(self, item, value): | |
| 109 self.__setattr__(item, value) | |
| 110 | |
| 111 def __setattr__(self, name, value): | |
| 112 cx = self._sandbox.cx | |
| 113 jsobject = self._jsobject | |
| 114 | |
| 115 cx.define_property(jsobject, name, | |
| 116 self._wrap_to_js(value)) | |
| 117 | |
| 118 def __getitem__(self, item): | |
| 119 return self.__getattr__(item) | |
| 120 | |
| 121 def __getattr__(self, name): | |
| 122 cx = self._sandbox.cx | |
| 123 jsobject = self._jsobject | |
| 124 | |
| 125 return self._wrap_to_python(cx.get_property(jsobject, name)) | |
| 126 | |
| 127 def __contains__(self, item): | |
| 128 cx = self._sandbox.cx | |
| 129 jsobject = self._jsobject | |
| 130 | |
| 131 return cx.has_property(jsobject, item) | |
| 132 | |
| 133 def __iter__(self): | |
| 134 cx = self._sandbox.cx | |
| 135 jsobject = self._jsobject | |
| 136 | |
| 137 properties = cx.enumerate(jsobject) | |
| 138 for property in properties: | |
| 139 yield property | |
| 140 | |
| 141 class SafeJsFunctionWrapper(SafeJsObjectWrapper): | |
| 142 """ | |
| 143 Securely wraps a JS function to behave like any normal Python object. | |
| 144 """ | |
| 145 | |
| 146 def __init__(self, sandbox, jsfunction, this): | |
| 147 if not isinstance(jsfunction, pydermonkey.Function): | |
| 148 raise TypeError("Cannot wrap '%s' object" % | |
| 149 type(jsobject).__name__) | |
| 150 SafeJsObjectWrapper.__init__(self, sandbox, jsfunction, this) | |
| 151 | |
| 152 def __call__(self, *args): | |
| 153 cx = self._sandbox.cx | |
| 154 jsobject = self._jsobject | |
| 155 this = self._this | |
| 156 | |
| 157 arglist = [] | |
| 158 for arg in args: | |
| 159 arglist.append(self._wrap_to_js(arg)) | |
| 160 | |
| 161 obj = cx.call_function(this, jsobject, tuple(arglist)) | |
| 162 return self._wrap_to_python(obj) | |
| 163 | |
| 11 | 164 def format_stack(js_stack, open=open): |
| 0 | 165 """ |
| 166 Returns a formatted Python-esque stack traceback of the given | |
| 167 JS stack. | |
| 168 """ | |
| 169 | |
| 170 STACK_LINE =" File \"%(filename)s\", line %(lineno)d, in %(name)s" | |
| 171 | |
| 172 lines = [] | |
| 173 while js_stack: | |
| 174 script = js_stack['script'] | |
| 175 function = js_stack['function'] | |
| 176 if script: | |
| 177 frameinfo = dict(filename = script.filename, | |
| 178 lineno = js_stack['lineno'], | |
| 179 name = '<module>') | |
| 180 elif function and not function.is_python: | |
| 181 frameinfo = dict(filename = function.filename, | |
| 182 lineno = js_stack['lineno'], | |
| 183 name = function.name) | |
| 184 else: | |
| 185 frameinfo = None | |
| 186 if frameinfo: | |
| 187 lines.insert(0, STACK_LINE % frameinfo) | |
| 188 try: | |
| 189 filelines = open(frameinfo['filename']).readlines() | |
| 190 line = filelines[frameinfo['lineno'] - 1].strip() | |
| 191 lines.insert(1, " %s" % line) | |
| 192 except Exception: | |
| 193 pass | |
| 194 js_stack = js_stack['caller'] | |
| 195 lines.insert(0, "Traceback (most recent call last):") | |
| 196 return '\n'.join(lines) | |
| 197 | |
| 198 def jsexposed(name=None, on=None): | |
| 199 """ | |
| 200 Decorator used to expose the decorated function or method to | |
| 201 untrusted JS. | |
| 202 | |
| 203 'name' is an optional alternative name for the function. | |
| 204 | |
| 205 'on' is an optional SafeJsObjectWrapper that the function can be | |
| 206 automatically attached as a property to. | |
| 207 """ | |
| 208 | |
| 209 if callable(name): | |
| 210 func = name | |
| 211 func.__jsexposed__ = True | |
| 212 return func | |
| 213 | |
| 214 def make_exposed(func): | |
| 215 if name: | |
| 216 func.__name__ = name | |
| 217 func.__jsexposed__ = True | |
| 218 if on: | |
| 219 on[func.__name__] = func | |
| 220 return func | |
| 221 return make_exposed | |
| 222 | |
| 223 class JsExposedObject(object): | |
| 224 """ | |
| 225 Trivial base/mixin class for any Python classes that choose to | |
| 226 expose themselves to JS code. | |
| 227 """ | |
| 228 | |
| 229 pass | |
| 230 | |
| 231 class JsSandbox(object): | |
| 232 """ | |
| 233 A JS runtime and associated functionality capable of securely | |
| 234 loading and executing scripts. | |
| 235 """ | |
| 236 | |
| 11 | 237 def __init__(self, fs, watchdog=watchdog): |
| 0 | 238 rt = pydermonkey.Runtime() |
| 239 cx = rt.new_context() | |
|
2
b6f9d743a2b5
Refined require() implementation.
Atul Varma <varmaa@toolness.com>
parents:
1
diff
changeset
|
240 root_proto = cx.new_object() |
|
b6f9d743a2b5
Refined require() implementation.
Atul Varma <varmaa@toolness.com>
parents:
1
diff
changeset
|
241 cx.init_standard_classes(root_proto) |
|
b6f9d743a2b5
Refined require() implementation.
Atul Varma <varmaa@toolness.com>
parents:
1
diff
changeset
|
242 root = cx.new_object(None, root_proto) |
| 0 | 243 |
| 244 cx.set_operation_callback(self._opcb) | |
| 245 cx.set_throw_hook(self._throwhook) | |
| 246 watchdog.add_context(cx) | |
| 247 | |
| 11 | 248 self.fs = fs |
| 0 | 249 self.rt = rt |
| 250 self.cx = cx | |
| 251 self.curr_exc = None | |
| 252 self.py_stack = None | |
| 253 self.js_stack = None | |
| 11 | 254 self.__modules = {} |
| 0 | 255 self.__py_to_js = {} |
| 256 self.__type_protos = {} | |
| 11 | 257 self.__globals = {} |
| 258 self.__root_proto = root_proto | |
| 0 | 259 self.root = self.wrap_jsobject(root, root) |
| 260 | |
| 11 | 261 def set_globals(self, **globals): |
| 262 self.__globals.update(globals) | |
| 263 self._install_globals(self.root) | |
| 264 | |
| 0 | 265 def finish(self): |
| 266 """ | |
| 267 Cleans up all resources used by the sandbox, breaking any reference | |
| 268 cycles created due to issue #2 in pydermonkey: | |
| 269 | |
| 270 http://code.google.com/p/pydermonkey/issues/detail?id=2 | |
| 271 """ | |
| 272 | |
| 273 for jsobj in self.__py_to_js.values(): | |
| 274 self.cx.clear_object_private(jsobj) | |
| 275 del self.__py_to_js | |
| 276 del self.__type_protos | |
| 277 del self.curr_exc | |
| 278 del self.py_stack | |
| 279 del self.js_stack | |
| 280 del self.cx | |
| 281 del self.rt | |
| 282 | |
| 283 def _opcb(self, cx): | |
| 284 # Don't do anything; if a keyboard interrupt was triggered, | |
| 285 # it'll get raised here automatically. | |
| 286 pass | |
| 287 | |
| 288 def _throwhook(self, cx): | |
| 289 curr_exc = cx.get_pending_exception() | |
| 290 if self.curr_exc != curr_exc: | |
| 291 self.curr_exc = curr_exc | |
| 292 self.py_stack = traceback.extract_stack() | |
| 293 self.js_stack = cx.get_stack() | |
| 294 | |
| 295 def __wrap_pycallable(self, func, pyproto=None): | |
| 296 if func in self.__py_to_js: | |
| 297 return self.__py_to_js[func] | |
| 298 | |
| 299 if hasattr(func, '__name__'): | |
| 300 name = func.__name__ | |
| 301 else: | |
| 302 name = "" | |
| 303 | |
| 304 if pyproto: | |
| 305 def wrapper(func_cx, this, args): | |
| 306 try: | |
| 307 arglist = [] | |
| 308 for arg in args: | |
| 309 arglist.append(self.wrap_jsobject(arg)) | |
| 310 instance = func_cx.get_object_private(this) | |
| 311 if instance is None or not isinstance(instance, pyproto): | |
| 312 raise pydermonkey.error("Method type mismatch") | |
| 313 | |
| 314 # TODO: Fill in extra required params with | |
| 315 # pymonkey.undefined? or automatically throw an | |
| 316 # exception to calling js code? | |
| 317 return self.wrap_pyobject(func(instance, *arglist)) | |
| 318 except pydermonkey.error: | |
| 319 raise | |
| 320 except Exception: | |
| 321 raise InternalError() | |
| 322 else: | |
| 323 def wrapper(func_cx, this, args): | |
| 324 try: | |
| 325 arglist = [] | |
| 326 for arg in args: | |
| 327 arglist.append(self.wrap_jsobject(arg)) | |
| 328 | |
| 329 # TODO: Fill in extra required params with | |
| 330 # pymonkey.undefined? or automatically throw an | |
| 331 # exception to calling js code? | |
| 332 return self.wrap_pyobject(func(*arglist)) | |
| 333 except pydermonkey.error: | |
| 334 raise | |
| 335 except Exception: | |
| 336 raise InternalError() | |
| 337 wrapper.wrapped_pyobject = func | |
| 338 wrapper.__name__ = name | |
| 339 | |
| 340 jsfunc = self.cx.new_function(wrapper, name) | |
| 341 self.__py_to_js[func] = jsfunc | |
| 342 | |
| 343 return jsfunc | |
| 344 | |
| 345 def __wrap_pyinstance(self, value): | |
| 346 pyproto = type(value) | |
| 347 if pyproto not in self.__type_protos: | |
| 348 jsproto = self.cx.new_object() | |
| 349 if hasattr(pyproto, '__jsprops__'): | |
| 350 define_getter = self.cx.get_property(jsproto, | |
| 351 '__defineGetter__') | |
| 352 define_setter = self.cx.get_property(jsproto, | |
| 353 '__defineSetter__') | |
| 354 for name in pyproto.__jsprops__: | |
| 355 prop = getattr(pyproto, name) | |
| 356 if not type(prop) == property: | |
| 357 raise TypeError("Expected attribute '%s' to " | |
| 358 "be a property" % name) | |
| 359 getter = None | |
| 360 setter = None | |
| 361 if prop.fget: | |
| 362 getter = self.__wrap_pycallable(prop.fget, | |
| 363 pyproto) | |
| 364 if prop.fset: | |
| 365 setter = self.__wrap_pycallable(prop.fset, | |
| 366 pyproto) | |
| 367 if getter: | |
| 368 self.cx.call_function(jsproto, | |
| 369 define_getter, | |
| 370 (name, getter)) | |
| 371 if setter: | |
| 372 self.cx.call_function(jsproto, | |
| 373 define_setter, | |
| 374 (name, setter,)) | |
| 375 for name in dir(pyproto): | |
| 376 attr = getattr(pyproto, name) | |
| 377 if (isinstance(attr, types.UnboundMethodType) and | |
| 378 hasattr(attr, '__jsexposed__') and | |
| 379 attr.__jsexposed__): | |
| 380 jsmethod = self.__wrap_pycallable(attr, pyproto) | |
| 381 self.cx.define_property(jsproto, name, jsmethod) | |
| 382 self.__type_protos[pyproto] = jsproto | |
| 383 return self.cx.new_object(value, self.__type_protos[pyproto]) | |
| 384 | |
| 385 def wrap_pyobject(self, value): | |
| 386 """ | |
| 387 Wraps the given Python object for export to untrusted JS. | |
| 388 | |
| 389 If the Python object isn't of a type that can be exposed to JS, | |
| 390 a TypeError is raised. | |
| 391 """ | |
| 392 | |
| 393 if (isinstance(value, (int, basestring, float, bool)) or | |
| 394 value is pydermonkey.undefined or | |
| 395 value is None): | |
| 396 return value | |
| 397 if isinstance(value, SafeJsObjectWrapper): | |
| 398 # It's already wrapped, just unwrap it. | |
| 399 return value.wrapped_jsobject | |
| 400 elif callable(value): | |
| 401 if not (hasattr(value, '__jsexposed__') and | |
| 402 value.__jsexposed__): | |
| 403 raise ValueError("Callable isn't configured for exposure " | |
| 404 "to untrusted JS code") | |
| 405 return self.__wrap_pycallable(value) | |
| 406 elif isinstance(value, JsExposedObject): | |
| 407 return self.__wrap_pyinstance(value) | |
| 408 else: | |
| 409 raise TypeError("Can't expose objects of type '%s' to JS." % | |
| 410 type(value).__name__) | |
| 411 | |
| 412 def wrap_jsobject(self, jsvalue, this=None): | |
| 413 """ | |
| 414 Wraps the given pydermonkey.Object for import to trusted | |
| 415 Python code. If the type is just a primitive, it's simply | |
| 416 returned, since no wrapping is needed. | |
| 417 """ | |
| 418 | |
| 419 if this is None: | |
| 420 this = self.root.wrapped_jsobject | |
| 421 if isinstance(jsvalue, pydermonkey.Function): | |
| 422 if jsvalue.is_python: | |
| 423 # It's a Python function, just unwrap it. | |
| 424 return self.cx.get_object_private(jsvalue).wrapped_pyobject | |
| 425 return SafeJsFunctionWrapper(self, jsvalue, this) | |
| 426 elif isinstance(jsvalue, pydermonkey.Object): | |
| 427 # It's a wrapped Python object instance, just unwrap it. | |
| 428 instance = self.cx.get_object_private(jsvalue) | |
| 429 if instance: | |
| 430 if not isinstance(instance, JsExposedObject): | |
| 431 raise AssertionError("Object private is not of type " | |
| 432 "JsExposedObject") | |
| 433 return instance | |
| 434 else: | |
| 435 return SafeJsObjectWrapper(self, jsvalue, this) | |
| 436 else: | |
| 437 # It's a primitive value. | |
| 438 return jsvalue | |
| 439 | |
| 440 def new_array(self, *contents): | |
| 441 array = self.wrap_jsobject(self.cx.new_array_object()) | |
| 442 for item in contents: | |
| 443 array.push(item) | |
| 444 return array | |
| 445 | |
| 446 def new_object(self, **contents): | |
| 447 obj = self.wrap_jsobject(self.cx.new_object()) | |
| 448 for name in contents: | |
| 449 obj[name] = contents[name] | |
| 450 return obj | |
| 451 | |
| 11 | 452 def get_calling_script(self): |
| 453 frame = self.cx.get_stack()['caller'] | |
| 454 curr_script = None | |
| 455 while frame and curr_script is None: | |
| 456 if frame['function'] and frame['function'].filename: | |
| 457 curr_script = frame['function'].filename | |
| 458 elif frame['script']: | |
| 459 curr_script = frame['script'].filename | |
| 460 frame = frame['caller'] | |
| 461 | |
| 462 if curr_script is None: | |
| 463 raise RuntimeError("Can't find calling script") | |
| 464 return curr_script | |
| 465 | |
| 466 def _install_globals(self, object): | |
| 467 for name in self.__globals: | |
| 468 object[name] = self.__globals[name] | |
| 469 object['require'] = self._require | |
| 470 | |
| 471 @jsexposed(name='require') | |
| 472 def _require(self, path): | |
| 473 filename = self.fs.find_module(self.get_calling_script(), path) | |
| 474 if not filename: | |
| 475 raise pydermonkey.error('Module not found: %s' % path) | |
| 476 if not filename in self.__modules: | |
| 477 cx = self.cx | |
| 478 module = cx.new_object(None, self.__root_proto) | |
| 479 cx.init_standard_classes(module) | |
| 480 exports = cx.new_object() | |
| 481 cx.define_property(module, 'exports', exports) | |
| 482 self._install_globals(self.wrap_jsobject(module)) | |
| 483 self.__modules[filename] = self.wrap_jsobject(exports) | |
| 484 contents = self.fs.open(filename).read() | |
| 485 cx.evaluate_script(module, contents, filename, 1) | |
| 486 return self.__modules[filename] | |
| 0 | 487 |
|
6
97adec8c8127
Now passing all CommonJS SecurableModule compliance tests.
Atul Varma <varmaa@toolness.com>
parents:
5
diff
changeset
|
488 def run_script(self, contents, filename='<string>', lineno=1, |
| 11 | 489 callback=None, stderr=sys.stderr): |
| 0 | 490 """ |
| 491 Runs the given JS script, returning 0 on success, -1 on failure. | |
| 492 """ | |
| 493 | |
| 494 retval = -1 | |
| 495 cx = self.cx | |
| 496 try: | |
| 497 result = cx.evaluate_script(self.root.wrapped_jsobject, | |
|
6
97adec8c8127
Now passing all CommonJS SecurableModule compliance tests.
Atul Varma <varmaa@toolness.com>
parents:
5
diff
changeset
|
498 contents, filename, lineno) |
| 0 | 499 if callback: |
| 500 callback(self.wrap_jsobject(result)) | |
| 501 retval = 0 | |
| 502 except pydermonkey.error, e: | |
| 11 | 503 params = dict( |
| 504 stack_trace = format_stack(self.js_stack, self.fs.open), | |
| 505 error = e.args[1] | |
| 506 ) | |
| 507 stderr.write("%(stack_trace)s\n%(error)s\n" % params) | |
| 0 | 508 except InternalError, e: |
| 11 | 509 stderr.write("An internal error occurred.\n") |
| 510 traceback.print_tb(e.exc_info[2], None, stderr) | |
| 511 stderr.write("%s\n" % e.exc_info[1]) | |
| 0 | 512 return retval |
|
1
ab09b8a10876
Added trivial half-baked implementation of securable modules.
Atul Varma <varmaa@toolness.com>
parents:
0
diff
changeset
|
513 |
| 14 | 514 class HttpFileSystem(object): |
| 515 def __init__(self, base_url): | |
| 516 self.base_url = base_url | |
| 517 | |
| 518 def find_module(self, curr_url, path): | |
| 519 import urlparse | |
| 520 | |
| 521 if path.startswith("."): | |
| 522 base_url = curr_url | |
| 523 else: | |
| 524 base_url = self.base_url | |
| 525 | |
| 526 url = "%s.js" % urlparse.urljoin(base_url, path) | |
| 527 if not url.startswith(self.base_url): | |
| 528 return None | |
| 529 return url | |
| 530 | |
| 531 def open(self, url): | |
| 532 import urllib | |
| 533 | |
| 534 return urllib.urlopen(url) | |
| 535 | |
| 11 | 536 class SandboxedFileSystem(object): |
| 537 def __init__(self, root_dir): | |
|
3
14d8d73774d7
Refactored securable module loader.
Atul Varma <varmaa@toolness.com>
parents:
2
diff
changeset
|
538 self.root_dir = root_dir |
|
2
b6f9d743a2b5
Refined require() implementation.
Atul Varma <varmaa@toolness.com>
parents:
1
diff
changeset
|
539 |
| 11 | 540 def find_module(self, curr_script, path): |
| 14 | 541 import os |
| 542 | |
| 11 | 543 if path.startswith("."): |
| 544 base_dir = os.path.dirname(curr_script) | |
| 545 else: | |
| 546 base_dir = self.root_dir | |
|
2
b6f9d743a2b5
Refined require() implementation.
Atul Varma <varmaa@toolness.com>
parents:
1
diff
changeset
|
547 |
| 11 | 548 ospath = path.replace('/', os.path.sep) |
| 549 filename = os.path.join(base_dir, "%s.js" % ospath) | |
| 550 filename = os.path.normpath(filename) | |
| 551 if (filename.startswith(self.root_dir) and | |
| 552 (os.path.exists(filename) and | |
| 553 not os.path.isdir(filename))): | |
| 554 return filename | |
| 555 else: | |
| 556 return None | |
|
3
14d8d73774d7
Refactored securable module loader.
Atul Varma <varmaa@toolness.com>
parents:
2
diff
changeset
|
557 |
| 11 | 558 def open(self, filename): |
| 559 return open(filename, 'r') |
