Show More
@@ -21,7 +21,7 b' import sys' | |||||
21 | from urllib2 import urlopen |
|
21 | from urllib2 import urlopen | |
22 |
|
22 | |||
23 | # Our own packages |
|
23 | # Our own packages | |
24 | from IPython.core.error import TryNext, StdinNotImplementedError |
|
24 | from IPython.core.error import TryNext, StdinNotImplementedError, UsageError | |
25 | from IPython.core.macro import Macro |
|
25 | from IPython.core.macro import Macro | |
26 | from IPython.core.magic import Magics, magics_class, line_magic |
|
26 | from IPython.core.magic import Magics, magics_class, line_magic | |
27 | from IPython.core.oinspect import find_file, find_source_lines |
|
27 | from IPython.core.oinspect import find_file, find_source_lines | |
@@ -73,6 +73,8 b' class CodeMagics(Magics):' | |||||
73 | """ |
|
73 | """ | |
74 |
|
74 | |||
75 | opts,args = self.parse_options(parameter_s,'fra',mode='list') |
|
75 | opts,args = self.parse_options(parameter_s,'fra',mode='list') | |
|
76 | if not args: | |||
|
77 | raise UsageError('Missing filename.') | |||
76 | raw = 'r' in opts |
|
78 | raw = 'r' in opts | |
77 | force = 'f' in opts |
|
79 | force = 'f' in opts | |
78 | append = 'a' in opts |
|
80 | append = 'a' in opts | |
@@ -178,6 +180,9 b' class CodeMagics(Magics):' | |||||
178 | %load http://www.example.com/myscript.py |
|
180 | %load http://www.example.com/myscript.py | |
179 | """ |
|
181 | """ | |
180 | opts,args = self.parse_options(arg_s,'y') |
|
182 | opts,args = self.parse_options(arg_s,'y') | |
|
183 | if not args: | |||
|
184 | raise UsageError('Missing filename, URL, input history range, ' | |||
|
185 | 'or macro.') | |||
181 |
|
186 | |||
182 | contents = self.shell.find_user_code(args) |
|
187 | contents = self.shell.find_user_code(args) | |
183 | l = len(contents) |
|
188 | l = len(contents) |
@@ -16,6 +16,7 b'' | |||||
16 | import os |
|
16 | import os | |
17 |
|
17 | |||
18 | # Our own packages |
|
18 | # Our own packages | |
|
19 | from IPython.core.error import UsageError | |||
19 | from IPython.core.magic import Magics, magics_class, line_magic |
|
20 | from IPython.core.magic import Magics, magics_class, line_magic | |
20 |
|
21 | |||
21 | #----------------------------------------------------------------------------- |
|
22 | #----------------------------------------------------------------------------- | |
@@ -56,14 +57,20 b' class ExtensionMagics(Magics):' | |||||
56 | @line_magic |
|
57 | @line_magic | |
57 | def load_ext(self, module_str): |
|
58 | def load_ext(self, module_str): | |
58 | """Load an IPython extension by its module name.""" |
|
59 | """Load an IPython extension by its module name.""" | |
|
60 | if not module_str: | |||
|
61 | raise UsageError('Missing module name.') | |||
59 | return self.shell.extension_manager.load_extension(module_str) |
|
62 | return self.shell.extension_manager.load_extension(module_str) | |
60 |
|
63 | |||
61 | @line_magic |
|
64 | @line_magic | |
62 | def unload_ext(self, module_str): |
|
65 | def unload_ext(self, module_str): | |
63 | """Unload an IPython extension by its module name.""" |
|
66 | """Unload an IPython extension by its module name.""" | |
|
67 | if not module_str: | |||
|
68 | raise UsageError('Missing module name.') | |||
64 | self.shell.extension_manager.unload_extension(module_str) |
|
69 | self.shell.extension_manager.unload_extension(module_str) | |
65 |
|
70 | |||
66 | @line_magic |
|
71 | @line_magic | |
67 | def reload_ext(self, module_str): |
|
72 | def reload_ext(self, module_str): | |
68 | """Reload an IPython extension by its module name.""" |
|
73 | """Reload an IPython extension by its module name.""" | |
|
74 | if not module_str: | |||
|
75 | raise UsageError('Missing module name.') | |||
69 | self.shell.extension_manager.reload_extension(module_str) |
|
76 | self.shell.extension_manager.reload_extension(module_str) |
@@ -19,7 +19,7 b' import sys' | |||||
19 |
|
19 | |||
20 | # Our own packages |
|
20 | # Our own packages | |
21 | from IPython.core import page |
|
21 | from IPython.core import page | |
22 | from IPython.core.error import StdinNotImplementedError |
|
22 | from IPython.core.error import StdinNotImplementedError, UsageError | |
23 | from IPython.core.magic import Magics, magics_class, line_magic |
|
23 | from IPython.core.magic import Magics, magics_class, line_magic | |
24 | from IPython.testing.skipdoctest import skip_doctest |
|
24 | from IPython.testing.skipdoctest import skip_doctest | |
25 | from IPython.utils.encoding import DEFAULT_ENCODING |
|
25 | from IPython.utils.encoding import DEFAULT_ENCODING | |
@@ -92,6 +92,8 b' class NamespaceMagics(Magics):' | |||||
92 | @line_magic |
|
92 | @line_magic | |
93 | def psource(self, parameter_s='', namespaces=None): |
|
93 | def psource(self, parameter_s='', namespaces=None): | |
94 | """Print (or run through pager) the source code for an object.""" |
|
94 | """Print (or run through pager) the source code for an object.""" | |
|
95 | if not parameter_s: | |||
|
96 | raise UsageError('Missing object name.') | |||
95 | self.shell._inspect('psource',parameter_s, namespaces) |
|
97 | self.shell._inspect('psource',parameter_s, namespaces) | |
96 |
|
98 | |||
97 | @line_magic |
|
99 | @line_magic |
@@ -681,6 +681,9 b' class OSMagics(Magics):' | |||||
681 | %pycat myMacro |
|
681 | %pycat myMacro | |
682 | %pycat http://www.example.com/myscript.py |
|
682 | %pycat http://www.example.com/myscript.py | |
683 | """ |
|
683 | """ | |
|
684 | if not parameter_s: | |||
|
685 | raise UsageError('Missing filename, URL, input history range, ' | |||
|
686 | 'or macro.') | |||
684 |
|
687 | |||
685 | try : |
|
688 | try : | |
686 | cont = self.shell.find_user_code(parameter_s) |
|
689 | cont = self.shell.find_user_code(parameter_s) |
@@ -613,7 +613,6 b' class MainWindow(QtGui.QMainWindow):' | |||||
613 | self.all_magic_menu.clear() |
|
613 | self.all_magic_menu.clear() | |
614 |
|
614 | |||
615 |
|
615 | |||
616 | protected_magic = set(["more","less","load_ext","pycat","loadpy","load","save","psource"]) |
|
|||
617 | mlist=ast.literal_eval(listofmagic) |
|
616 | mlist=ast.literal_eval(listofmagic) | |
618 | for magic in mlist: |
|
617 | for magic in mlist: | |
619 | cell = (magic['type'] == 'cell') |
|
618 | cell = (magic['type'] == 'cell') | |
@@ -625,11 +624,7 b' class MainWindow(QtGui.QMainWindow):' | |||||
625 | prefix='%' |
|
624 | prefix='%' | |
626 | magic_menu = self._get_magic_menu(mclass) |
|
625 | magic_menu = self._get_magic_menu(mclass) | |
627 |
|
626 | |||
628 | if name in protected_magic: |
|
627 | pmagic = '%s%s'%(prefix,name) | |
629 | suffix = '?' |
|
|||
630 | else : |
|
|||
631 | suffix = '' |
|
|||
632 | pmagic = '%s%s%s'%(prefix,name,suffix) |
|
|||
633 |
|
628 | |||
634 | xaction = QtGui.QAction(pmagic, |
|
629 | xaction = QtGui.QAction(pmagic, | |
635 | self, |
|
630 | self, |
@@ -30,6 +30,7 b' from IPython.core.interactiveshell import (' | |||||
30 | from IPython.core import page |
|
30 | from IPython.core import page | |
31 | from IPython.core.autocall import ZMQExitAutocall |
|
31 | from IPython.core.autocall import ZMQExitAutocall | |
32 | from IPython.core.displaypub import DisplayPublisher |
|
32 | from IPython.core.displaypub import DisplayPublisher | |
|
33 | from IPython.core.error import UsageError | |||
33 | from IPython.core.magics import MacroToEdit, CodeMagics |
|
34 | from IPython.core.magics import MacroToEdit, CodeMagics | |
34 | from IPython.core.magic import magics_class, line_magic, Magics |
|
35 | from IPython.core.magic import magics_class, line_magic, Magics | |
35 | from IPython.core.payloadpage import install_payload_page |
|
36 | from IPython.core.payloadpage import install_payload_page | |
@@ -349,6 +350,9 b' class KernelMagics(Magics):' | |||||
349 | """Show a file through the pager. |
|
350 | """Show a file through the pager. | |
350 |
|
351 | |||
351 | Files ending in .py are syntax-highlighted.""" |
|
352 | Files ending in .py are syntax-highlighted.""" | |
|
353 | if not arg_s: | |||
|
354 | raise UsageError('Missing filename.') | |||
|
355 | ||||
352 | cont = open(arg_s).read() |
|
356 | cont = open(arg_s).read() | |
353 | if arg_s.endswith('.py'): |
|
357 | if arg_s.endswith('.py'): | |
354 | cont = self.shell.pycolorize(cont) |
|
358 | cont = self.shell.pycolorize(cont) |
General Comments 0
You need to be logged in to leave comments.
Login now