##// END OF EJS Templates
find_user_code binary fallback
Matthias BUSSONNIER -
Show More
@@ -30,6 +30,8 b' import runpy'
30 import sys
30 import sys
31 import tempfile
31 import tempfile
32 import types
32 import types
33 import urllib
34 from io import BytesIO,TextIOWrapper
33
35
34 try:
36 try:
35 from contextlib import nested
37 from contextlib import nested
@@ -2757,13 +2759,14 b' class InteractiveShell(SingletonConfigurable, Magic):'
2757 If true (default), retrieve raw history. Has no effect on the other
2759 If true (default), retrieve raw history. Has no effect on the other
2758 retrieval mechanisms.
2760 retrieval mechanisms.
2759
2761
2760 py_only : bool
2762 py_only : bool (default False)
2761 Only try to fetch python code, do not try alternative methods to decode file
2763 Only try to fetch python code, do not try alternative methods to decode file
2762 if unicode fails.
2764 if unicode fails.
2763
2765
2764 Returns
2766 Returns
2765 -------
2767 -------
2766 A string of code.
2768 A string of code. If py_only set to False, might return raw bytes if unable
2769 to decode target.
2767
2770
2768 ValueError is raised if nothing is found, and TypeError if it evaluates
2771 ValueError is raised if nothing is found, and TypeError if it evaluates
2769 to an object of another type. In each case, .args[0] is a printable
2772 to an object of another type. In each case, .args[0] is a printable
@@ -2777,8 +2780,11 b' class InteractiveShell(SingletonConfigurable, Magic):'
2777 if utarget.startswith(('http://', 'https://')):
2780 if utarget.startswith(('http://', 'https://')):
2778 return openpy.read_py_url(utarget, skip_encoding_cookie=True)
2781 return openpy.read_py_url(utarget, skip_encoding_cookie=True)
2779 except UnicodeDecodeError:
2782 except UnicodeDecodeError:
2783 print('other url');
2780 if not py_only :
2784 if not py_only :
2781 return openpy.read_py_url(utarget, skip_encoding_cookie=False)
2785 response = urllib.urlopen(target)
2786 buffer = BytesIO(response.read())
2787 return buffer.read()
2782 raise ValueError(("'%s' seem to be unreadable.") % utarget)
2788 raise ValueError(("'%s' seem to be unreadable.") % utarget)
2783
2789
2784 try :
2790 try :
@@ -2789,7 +2795,8 b' class InteractiveShell(SingletonConfigurable, Magic):'
2789 pass
2795 pass
2790 except UnicodeDecodeError :
2796 except UnicodeDecodeError :
2791 if not py_only :
2797 if not py_only :
2792 return openpy.read_py_file(utarget, skip_encoding_cookie=False)
2798 with open(pyfile) as f :
2799 return f.read()
2793 raise ValueError(("'%s' seem to be unreadable.") % target)
2800 raise ValueError(("'%s' seem to be unreadable.") % target)
2794
2801
2795 if os.path.isfile(target): # Read file
2802 if os.path.isfile(target): # Read file
@@ -2797,7 +2804,8 b' class InteractiveShell(SingletonConfigurable, Magic):'
2797 return openpy.read_py_file(target, skip_encoding_cookie=True)
2804 return openpy.read_py_file(target, skip_encoding_cookie=True)
2798 except UnicodeDecodeError :
2805 except UnicodeDecodeError :
2799 if not py_only :
2806 if not py_only :
2800 return openpy.read_py_file(utarget, skip_encoding_cookie=False)
2807 with open(target) as f :
2808 return f.read()
2801 raise ValueError(("'%s' seem to be unreadable.") % target)
2809 raise ValueError(("'%s' seem to be unreadable.") % target)
2802
2810
2803 try: # User namespace
2811 try: # User namespace
General Comments 0
You need to be logged in to leave comments. Login now