Show More
@@ -5,7 +5,7 b' Class which mimics a module.' | |||||
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 27 |
|
8 | $Id: FakeModule.py 2754 2007-09-09 10:16:59Z 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> | |
@@ -25,28 +25,19 b' class FakeModule(types.ModuleType):' | |||||
25 | sessions. |
|
25 | sessions. | |
26 |
|
26 | |||
27 | Do NOT use this code for anything other than this IPython private hack.""" |
|
27 | Do NOT use this code for anything other than this IPython private hack.""" | |
28 | def __init__(self,adict): |
|
|||
29 |
|
28 | |||
|
29 | def __init__(self,adict=None): | |||
|
30 | ||||
|
31 | # tmp to force __dict__ instance creation, else self.__dict__ fails | |||
|
32 | self.__iptmp = None | |||
|
33 | ||||
30 | # It seems pydoc (and perhaps others) needs any module instance to |
|
34 | # It seems pydoc (and perhaps others) needs any module instance to | |
31 | # implement a __nonzero__ method, so we add it if missing: |
|
35 | # implement a __nonzero__ method, so we add it if missing: | |
32 | if '__nonzero__' not in adict: |
|
36 | self.__dict__.setdefault('__nonzero__',lambda : True) | |
33 | def __nonzero__(): |
|
37 | self.__dict__.setdefault('__file__',__file__) | |
34 | return 1 |
|
|||
35 | adict['__nonzero__'] = __nonzero__ |
|
|||
36 |
|
38 | |||
37 | self._dict_ = adict |
|
39 | # cleanup our temp trick | |
|
40 | del self.__iptmp | |||
38 |
|
41 | |||
39 | # modules should have a __file__ attribute |
|
42 | if adict is not None: | |
40 | adict.setdefault('__file__',__file__) |
|
43 | self.__dict__.update(adict) | |
41 |
|
||||
42 | def __getattr__(self,key): |
|
|||
43 | try: |
|
|||
44 | return self._dict_[key] |
|
|||
45 | except KeyError, e: |
|
|||
46 | raise AttributeError("FakeModule object has no attribute %s" % e) |
|
|||
47 |
|
||||
48 | def __str__(self): |
|
|||
49 | return "<IPython.FakeModule instance>" |
|
|||
50 |
|
||||
51 | def __repr__(self): |
|
|||
52 | return str(self) |
|
@@ -1,7 +1,7 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | """Magic functions for InteractiveShell. |
|
2 | """Magic functions for InteractiveShell. | |
3 |
|
3 | |||
4 |
$Id: Magic.py 274 |
|
4 | $Id: Magic.py 2754 2007-09-09 10:16:59Z fperez $""" | |
5 |
|
5 | |||
6 | #***************************************************************************** |
|
6 | #***************************************************************************** | |
7 | # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and |
|
7 | # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and | |
@@ -1522,12 +1522,15 b' Currently the magic system has the following functions:\\n"""' | |||||
1522 | prog_ns = self.shell.user_ns |
|
1522 | prog_ns = self.shell.user_ns | |
1523 | __name__save = self.shell.user_ns['__name__'] |
|
1523 | __name__save = self.shell.user_ns['__name__'] | |
1524 | prog_ns['__name__'] = '__main__' |
|
1524 | prog_ns['__name__'] = '__main__' | |
|
1525 | main_mod = FakeModule(prog_ns) | |||
1525 | else: |
|
1526 | else: | |
1526 | if opts.has_key('n'): |
|
1527 | if opts.has_key('n'): | |
1527 | name = os.path.splitext(os.path.basename(filename))[0] |
|
1528 | name = os.path.splitext(os.path.basename(filename))[0] | |
1528 | else: |
|
1529 | else: | |
1529 | name = '__main__' |
|
1530 | name = '__main__' | |
1530 | prog_ns = {'__name__':name} |
|
1531 | main_mod = FakeModule() | |
|
1532 | prog_ns = main_mod.__dict__ | |||
|
1533 | prog_ns['__name__'] = name | |||
1531 |
|
1534 | |||
1532 | # Since '%run foo' emulates 'python foo.py' at the cmd line, we must |
|
1535 | # Since '%run foo' emulates 'python foo.py' at the cmd line, we must | |
1533 | # set the __file__ global in the script's namespace |
|
1536 | # set the __file__ global in the script's namespace | |
@@ -1540,7 +1543,7 b' Currently the magic system has the following functions:\\n"""' | |||||
1540 | else: |
|
1543 | else: | |
1541 | restore_main = False |
|
1544 | restore_main = False | |
1542 |
|
1545 | |||
1543 |
sys.modules[prog_ns['__name__']] = |
|
1546 | sys.modules[prog_ns['__name__']] = main_mod | |
1544 |
|
1547 | |||
1545 | stats = None |
|
1548 | stats = None | |
1546 | try: |
|
1549 | try: |
@@ -6,7 +6,7 b' Requires Python 2.3 or newer.' | |||||
6 |
|
6 | |||
7 | This file contains all the classes and helper functions specific to IPython. |
|
7 | This file contains all the classes and helper functions specific to IPython. | |
8 |
|
8 | |||
9 |
$Id: iplib.py 274 |
|
9 | $Id: iplib.py 2754 2007-09-09 10:16:59Z fperez $ | |
10 | """ |
|
10 | """ | |
11 |
|
11 | |||
12 | #***************************************************************************** |
|
12 | #***************************************************************************** | |
@@ -2391,7 +2391,23 b' want to merge them back into the new files.""" % locals()' | |||||
2391 | """A safe version of the builtin execfile(). |
|
2391 | """A safe version of the builtin execfile(). | |
2392 |
|
2392 | |||
2393 | This version will never throw an exception, and knows how to handle |
|
2393 | This version will never throw an exception, and knows how to handle | |
2394 |
ipython logs as well. |
|
2394 | ipython logs as well. | |
|
2395 | ||||
|
2396 | :Parameters: | |||
|
2397 | fname : string | |||
|
2398 | Name of the file to be executed. | |||
|
2399 | ||||
|
2400 | where : tuple | |||
|
2401 | One or two namespaces, passed to execfile() as (globals,locals). | |||
|
2402 | If only one is given, it is passed as both. | |||
|
2403 | ||||
|
2404 | :Keywords: | |||
|
2405 | islog : boolean (False) | |||
|
2406 | ||||
|
2407 | quiet : boolean (True) | |||
|
2408 | ||||
|
2409 | exit_ignore : boolean (False) | |||
|
2410 | """ | |||
2395 |
|
2411 | |||
2396 | def syspath_cleanup(): |
|
2412 | def syspath_cleanup(): | |
2397 | """Internal cleanup routine for sys.path.""" |
|
2413 | """Internal cleanup routine for sys.path.""" | |
@@ -2424,6 +2440,7 b' want to merge them back into the new files.""" % locals()' | |||||
2424 | kw.setdefault('islog',0) |
|
2440 | kw.setdefault('islog',0) | |
2425 | kw.setdefault('quiet',1) |
|
2441 | kw.setdefault('quiet',1) | |
2426 | kw.setdefault('exit_ignore',0) |
|
2442 | kw.setdefault('exit_ignore',0) | |
|
2443 | ||||
2427 | first = xfile.readline() |
|
2444 | first = xfile.readline() | |
2428 | loghead = str(self.loghead_tpl).split('\n',1)[0].strip() |
|
2445 | loghead = str(self.loghead_tpl).split('\n',1)[0].strip() | |
2429 | xfile.close() |
|
2446 | xfile.close() |
@@ -1,3 +1,10 b'' | |||||
|
1 | 2007-09-09 Fernando Perez <Fernando.Perez@colorado.edu> | |||
|
2 | ||||
|
3 | * IPython/FakeModule.py (FakeModule.__init__): further fixes for | |||
|
4 | doctest support. | |||
|
5 | ||||
|
6 | * IPython/iplib.py (safe_execfile): minor docstring improvements. | |||
|
7 | ||||
1 | 2007-09-08 Ville Vainio <vivainio@gmail.com> |
|
8 | 2007-09-08 Ville Vainio <vivainio@gmail.com> | |
2 |
|
9 | |||
3 | * Magic.py (%pushd, %popd, %dirs): Fix dir stack - push *current* |
|
10 | * Magic.py (%pushd, %popd, %dirs): Fix dir stack - push *current* |
General Comments 0
You need to be logged in to leave comments.
Login now