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