##// END OF EJS Templates
use pathlib in utils/openpy.py
rushabh-v -
Show More
@@ -7,6 +7,7 b' Much of the code is taken from the tokenize module in Python 3.2.'
7
7
8 import io
8 import io
9 from io import TextIOWrapper, BytesIO
9 from io import TextIOWrapper, BytesIO
10 from pathlib import Path
10 import re
11 import re
11 from tokenize import open, detect_encoding
12 from tokenize import open, detect_encoding
12
13
@@ -72,11 +73,12 b' def read_py_file(filename, skip_encoding_cookie=True):'
72 -------
73 -------
73 A unicode string containing the contents of the file.
74 A unicode string containing the contents of the file.
74 """
75 """
75 with open(filename) as f: # the open function defined in this module.
76 filepath = Path(filename)
77 with filepath.open() as f: # the open function defined in this module.
76 if skip_encoding_cookie:
78 if skip_encoding_cookie:
77 return "".join(strip_encoding_cookie(f))
79 return "".join(strip_encoding_cookie(f))
78 else:
80 else:
79 return f.read()
81 return filepath.read_text()
80
82
81 def read_py_url(url, errors='replace', skip_encoding_cookie=True):
83 def read_py_url(url, errors='replace', skip_encoding_cookie=True):
82 """Read a Python file from a URL, using the encoding declared inside the file.
84 """Read a Python file from a URL, using the encoding declared inside the file.
General Comments 0
You need to be logged in to leave comments. Login now