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