From fcdc9f835fcac9249b510af3968ec3f013b49712 2012-08-27 17:02:36 From: Jörgen Stenarson Date: 2012-08-27 17:02:36 Subject: [PATCH] Make magic pycat print encoding_cookie --- diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index e8c471e..5527f51 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -2914,7 +2914,7 @@ class InteractiveShell(SingletonConfigurable): lines = self.history_manager.get_range_by_str(range_str, raw=raw) return "\n".join(x for _, _, x in lines) - def find_user_code(self, target, raw=True, py_only=False): + def find_user_code(self, target, raw=True, py_only=False, skip_encoding_cookie=True): """Get a code string from history, file, url, or a string or macro. This is mainly used by magic functions. @@ -2951,7 +2951,7 @@ class InteractiveShell(SingletonConfigurable): utarget = unquote_filename(target) try: if utarget.startswith(('http://', 'https://')): - return openpy.read_py_url(utarget, skip_encoding_cookie=True) + return openpy.read_py_url(utarget, skip_encoding_cookie=skip_encoding_cookie) except UnicodeDecodeError: if not py_only : response = urllib.urlopen(target) @@ -2967,7 +2967,7 @@ class InteractiveShell(SingletonConfigurable): for tgt in potential_target : if os.path.isfile(tgt): # Read file try : - return openpy.read_py_file(tgt, skip_encoding_cookie=True) + return openpy.read_py_file(tgt, skip_encoding_cookie=skip_encoding_cookie) except UnicodeDecodeError : if not py_only : with io_open(tgt,'r', encoding='latin1') as f : diff --git a/IPython/core/magics/osm.py b/IPython/core/magics/osm.py index d0e5d91..9bcd1bf 100644 --- a/IPython/core/magics/osm.py +++ b/IPython/core/magics/osm.py @@ -687,7 +687,7 @@ class OSMagics(Magics): 'or macro.') try : - cont = self.shell.find_user_code(parameter_s) + cont = self.shell.find_user_code(parameter_s, skip_encoding_cookie=False) except (ValueError, IOError): print "Error: no such file, variable, URL, history range or macro" return