Show More
@@ -30,6 +30,8 b' import runpy' | |||
|
30 | 30 | import sys |
|
31 | 31 | import tempfile |
|
32 | 32 | import types |
|
33 | import urllib | |
|
34 | from io import BytesIO,TextIOWrapper | |
|
33 | 35 | |
|
34 | 36 | try: |
|
35 | 37 | from contextlib import nested |
@@ -2757,13 +2759,14 b' class InteractiveShell(SingletonConfigurable, Magic):' | |||
|
2757 | 2759 | If true (default), retrieve raw history. Has no effect on the other |
|
2758 | 2760 | retrieval mechanisms. |
|
2759 | 2761 | |
|
2760 | py_only : bool | |
|
2762 | py_only : bool (default False) | |
|
2761 | 2763 | Only try to fetch python code, do not try alternative methods to decode file |
|
2762 | 2764 | if unicode fails. |
|
2763 | 2765 | |
|
2764 | 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 | 2771 | ValueError is raised if nothing is found, and TypeError if it evaluates |
|
2769 | 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 | 2780 | if utarget.startswith(('http://', 'https://')): |
|
2778 | 2781 | return openpy.read_py_url(utarget, skip_encoding_cookie=True) |
|
2779 | 2782 | except UnicodeDecodeError: |
|
2783 | print('other url'); | |
|
2780 | 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 | 2788 | raise ValueError(("'%s' seem to be unreadable.") % utarget) |
|
2783 | 2789 | |
|
2784 | 2790 | try : |
@@ -2789,7 +2795,8 b' class InteractiveShell(SingletonConfigurable, Magic):' | |||
|
2789 | 2795 | pass |
|
2790 | 2796 | except UnicodeDecodeError : |
|
2791 | 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 | 2800 | raise ValueError(("'%s' seem to be unreadable.") % target) |
|
2794 | 2801 | |
|
2795 | 2802 | if os.path.isfile(target): # Read file |
@@ -2797,7 +2804,8 b' class InteractiveShell(SingletonConfigurable, Magic):' | |||
|
2797 | 2804 | return openpy.read_py_file(target, skip_encoding_cookie=True) |
|
2798 | 2805 | except UnicodeDecodeError : |
|
2799 | 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 | 2809 | raise ValueError(("'%s' seem to be unreadable.") % target) |
|
2802 | 2810 | |
|
2803 | 2811 | try: # User namespace |
General Comments 0
You need to be logged in to leave comments.
Login now