##// END OF EJS Templates
Small fix to respect the __file__ attribute when using %run
fperez -
Show More

The requested changes are too big and content was truncated. Show full diff

@@ -1,51 +1,51 b''
1 1 # -*- coding: utf-8 -*-
2 2 """
3 3 Class which mimics a module.
4 4
5 5 Needed to allow pickle to correctly resolve namespaces during IPython
6 6 sessions.
7 7
8 $Id: FakeModule.py 1625 2006-08-12 10:34:44Z vivainio $"""
8 $Id: FakeModule.py 2169 2007-03-23 06:09:43Z fperez $"""
9 9
10 10 #*****************************************************************************
11 11 # Copyright (C) 2002-2004 Fernando Perez. <fperez@colorado.edu>
12 12 #
13 13 # Distributed under the terms of the BSD License. The full license is in
14 14 # the file COPYING, distributed as part of this software.
15 15 #*****************************************************************************
16 16
17 17 class FakeModule:
18 18 """Simple class with attribute access to fake a module.
19 19
20 20 This is not meant to replace a module, but to allow inserting a fake
21 21 module in sys.modules so that systems which rely on run-time module
22 22 importing (like shelve and pickle) work correctly in interactive IPython
23 23 sessions.
24 24
25 25 Do NOT use this code for anything other than this IPython private hack."""
26 26
27 27 def __init__(self,adict):
28 28
29 29 # It seems pydoc (and perhaps others) needs any module instance to
30 30 # implement a __nonzero__ method, so we add it if missing:
31 31 if '__nonzero__' not in adict:
32 32 def __nonzero__():
33 33 return 1
34 34 adict['__nonzero__'] = __nonzero__
35 35
36 36 self.__dict__ = adict
37 37
38 38 # modules should have a __file__ attribute
39 adict['__file__'] = __file__
39 adict.setdefault('__file__',__file__)
40 40
41 41 def __getattr__(self,key):
42 42 try:
43 43 return self.__dict__[key]
44 44 except KeyError, e:
45 45 raise AttributeError("FakeModule object has no attribute %s" % e)
46 46
47 47 def __str__(self):
48 48 return "<IPython.FakeModule instance>"
49 49
50 50 def __repr__(self):
51 51 return str(self)
1 NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
General Comments 0
You need to be logged in to leave comments. Login now