Show More
@@ -88,13 +88,8 b' class BuiltinTrap(Configurable):' | |||||
88 | self._orig_builtins[key] = orig |
|
88 | self._orig_builtins[key] = orig | |
89 | bdict[key] = value |
|
89 | bdict[key] = value | |
90 |
|
90 | |||
91 | def remove_builtin(self, key): |
|
91 | def remove_builtin(self, key, orig): | |
92 | """Remove an added builtin and re-set the original.""" |
|
92 | """Remove an added builtin and re-set the original.""" | |
93 | try: |
|
|||
94 | orig = self._orig_builtins.pop(key) |
|
|||
95 | except KeyError: |
|
|||
96 | pass |
|
|||
97 | else: |
|
|||
98 |
|
|
93 | if orig is BuiltinUndefined: | |
99 |
|
|
94 | del __builtin__.__dict__[key] | |
100 |
|
|
95 | else: | |
@@ -107,22 +102,11 b' class BuiltinTrap(Configurable):' | |||||
107 | for name, func in self.auto_builtins.iteritems(): |
|
102 | for name, func in self.auto_builtins.iteritems(): | |
108 | add_builtin(name, func) |
|
103 | add_builtin(name, func) | |
109 |
|
104 | |||
110 | # Keep in the builtins a flag for when IPython is active. We set it |
|
|||
111 | # with setdefault so that multiple nested IPythons don't clobber one |
|
|||
112 | # another. |
|
|||
113 | __builtin__.__dict__.setdefault('__IPYTHON__active', 0) |
|
|||
114 |
|
||||
115 | def deactivate(self): |
|
105 | def deactivate(self): | |
116 | """Remove any builtins which might have been added by add_builtins, or |
|
106 | """Remove any builtins which might have been added by add_builtins, or | |
117 | restore overwritten ones to their previous values.""" |
|
107 | restore overwritten ones to their previous values.""" | |
118 | # Note: must iterate over a static keys() list because we'll be |
|
|||
119 | # mutating the dict itself |
|
|||
120 | remove_builtin = self.remove_builtin |
|
108 | remove_builtin = self.remove_builtin | |
121 |
for key in self._orig_builtins. |
|
109 | for key, val in self._orig_builtins.iteritems(): | |
122 | remove_builtin(key) |
|
110 | remove_builtin(key, val) | |
123 | self._orig_builtins.clear() |
|
111 | self._orig_builtins.clear() | |
124 | self._builtins_added = False |
|
112 | self._builtins_added = False | |
125 | try: |
|
|||
126 | del __builtin__.__dict__['__IPYTHON__active'] |
|
|||
127 | except KeyError: |
|
|||
128 | pass |
|
@@ -605,6 +605,20 b' class InteractiveShell(SingletonConfigurable, Magic):' | |||||
605 | self.magic_logstart() |
|
605 | self.magic_logstart() | |
606 |
|
606 | |||
607 | def init_builtins(self): |
|
607 | def init_builtins(self): | |
|
608 | # A single, static flag that we set to True. Its presence indicates | |||
|
609 | # that an IPython shell has been created, and we make no attempts at | |||
|
610 | # removing on exit or representing the existence of more than one | |||
|
611 | # IPython at a time. | |||
|
612 | builtin_mod.__dict__['__IPYTHON__'] = True | |||
|
613 | ||||
|
614 | # In 0.11 we introduced '__IPYTHON__active' as an integer we'd try to | |||
|
615 | # manage on enter/exit, but with all our shells it's virtually | |||
|
616 | # impossible to get all the cases right. We're leaving the name in for | |||
|
617 | # those who adapted their codes to check for this flag, but will | |||
|
618 | # eventually remove it after a few more releases. | |||
|
619 | builtin_mod.__dict__['__IPYTHON__active'] = \ | |||
|
620 | 'Deprecated, check for __IPYTHON__' | |||
|
621 | ||||
608 | self.builtin_trap = BuiltinTrap(shell=self) |
|
622 | self.builtin_trap = BuiltinTrap(shell=self) | |
609 |
|
623 | |||
610 | def init_inspector(self): |
|
624 | def init_inspector(self): |
@@ -271,3 +271,8 b' class TestSystemRaw(unittest.TestCase):' | |||||
271 | """ |
|
271 | """ | |
272 | cmd = ur'''python -c "'åäö'" ''' |
|
272 | cmd = ur'''python -c "'åäö'" ''' | |
273 | _ip.shell.system_raw(cmd) |
|
273 | _ip.shell.system_raw(cmd) | |
|
274 | ||||
|
275 | ||||
|
276 | def test__IPYTHON__(): | |||
|
277 | # This shouldn't raise a NameError, that's all | |||
|
278 | __IPYTHON__ |
@@ -341,9 +341,6 b' class TerminalInteractiveShell(InteractiveShell):' | |||||
341 |
|
341 | |||
342 | more = False |
|
342 | more = False | |
343 |
|
343 | |||
344 | # Mark activity in the builtins |
|
|||
345 | __builtin__.__dict__['__IPYTHON__active'] += 1 |
|
|||
346 |
|
||||
347 | if self.has_readline: |
|
344 | if self.has_readline: | |
348 | self.readline_startup_hook(self.pre_readline) |
|
345 | self.readline_startup_hook(self.pre_readline) | |
349 | hlen_b4_cell = self.readline.get_current_history_length() |
|
346 | hlen_b4_cell = self.readline.get_current_history_length() | |
@@ -413,9 +410,6 b' class TerminalInteractiveShell(InteractiveShell):' | |||||
413 | hlen_b4_cell = \ |
|
410 | hlen_b4_cell = \ | |
414 | self._replace_rlhist_multiline(source_raw, hlen_b4_cell) |
|
411 | self._replace_rlhist_multiline(source_raw, hlen_b4_cell) | |
415 |
|
412 | |||
416 | # We are off again... |
|
|||
417 | __builtin__.__dict__['__IPYTHON__active'] -= 1 |
|
|||
418 |
|
||||
419 | # Turn off the exit flag, so the mainloop can be restarted if desired |
|
413 | # Turn off the exit flag, so the mainloop can be restarted if desired | |
420 | self.exit_now = False |
|
414 | self.exit_now = False | |
421 |
|
415 |
General Comments 0
You need to be logged in to leave comments.
Login now