1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
--- contrib/python/parso/py3/parso/cache.py (index)
+++ contrib/python/parso/py3/parso/cache.py (working tree)
@@ -135,6 +135,8 @@ def load_module(hashed_grammar, file_io, cache_path=None):
def _load_from_file_system(hashed_grammar, path, p_time, cache_path=None):
cache_path = _get_hashed_path(hashed_grammar, path, cache_path=cache_path)
try:
+ # SUBBOTNIK-2721 - Для безопасности отключаем загрузку с диска
+ raise FileNotFoundError
if p_time > os.path.getmtime(cache_path):
# Cache is outdated
return None
--- contrib/python/parso/py3/parso/file_io.py (index)
+++ contrib/python/parso/py3/parso/file_io.py (working tree)
@@ -2,6 +2,8 @@ import os
from pathlib import Path
from typing import Union
+import __res as res
+
class FileIO:
def __init__(self, path: Union[os.PathLike, str]):
@@ -13,6 +15,9 @@ class FileIO:
# We would like to read unicode here, but we cannot, because we are not
# sure if it is a valid unicode file. Therefore just read whatever is
# here.
+ data = res.resfs_read(self.path)
+ if data:
+ return data
with open(self.path, 'rb') as f:
return f.read()
--- contrib/python/parso/py3/parso/grammar.py (index)
+++ contrib/python/parso/py3/parso/grammar.py (working tree)
@@ -1,5 +1,6 @@
import hashlib
import os
+import pkgutil
from typing import Generic, TypeVar, Union, Dict, Optional, Any
from pathlib import Path
@@ -252,12 +253,13 @@ def load_grammar(*, version: str = None, path: str = None):
return _loaded_grammars[path]
except KeyError:
try:
- with open(path) as f:
- bnf_text = f.read()
+ bnf_text = pkgutil.get_data("parso", file).decode("utf-8")
+ if bnf_text is None:
+ raise FileNotFoundError
grammar = PythonGrammar(version_info, bnf_text)
return _loaded_grammars.setdefault(path, grammar)
- except FileNotFoundError:
+ except (FileNotFoundError, IOError):
message = "Python version %s.%s is currently not supported." % (
version_info.major, version_info.minor
)
--- contrib/python/parso/py3/tests/conftest.py (index)
+++ contrib/python/parso/py3/tests/conftest.py (working tree)
@@ -6,6 +6,7 @@ import os
from pathlib import Path
import pytest
+import yatest.common
import parso
from parso import cache
@@ -42,7 +43,7 @@ def pytest_addoption(parser):
def pytest_generate_tests(metafunc):
if 'normalizer_issue_case' in metafunc.fixturenames:
- base_dir = os.path.join(os.path.dirname(__file__), 'test', 'normalizer_issue_files')
+ base_dir = os.path.join(yatest.common.test_source_path(), 'normalizer_issue_files')
cases = list(colllect_normalizer_tests(base_dir))
metafunc.parametrize(
--- contrib/python/parso/py3/tests/test_cache.py (index)
+++ contrib/python/parso/py3/tests/test_cache.py (working tree)
@@ -34,6 +34,7 @@ def isolated_parso_cache(monkeypatch, tmpdir):
return cache_path
+@pytest.mark.skip("SUBBOTNIK-2721 Disable load cache from disk")
def test_modulepickling_change_cache_dir(tmpdir):
"""
ParserPickling should not save old cache when cache_directory is changed.
@@ -99,6 +100,7 @@ def test_modulepickling_simulate_deleted_cache(tmpdir):
assert cached2 is None
+@pytest.mark.skip
def test_cache_limit():
def cache_size():
return sum(len(v) for v in parser_cache.values())
@@ -129,6 +131,7 @@ class _FixedTimeFileIO(file_io.KnownContentFileIO):
return self._last_modified
+@pytest.mark.skip
@pytest.mark.parametrize('diff_cache', [False, True])
@pytest.mark.parametrize('use_file_io', [False, True])
def test_cache_last_used_update(diff_cache, use_file_io):
@@ -175,6 +178,7 @@ def test_inactive_cache(tmpdir, isolated_parso_cache):
assert not old_paths.intersection(os.listdir(raw_cache_path))
+@pytest.mark.skip
@skip_pypy
def test_permission_error(monkeypatch):
def save(*args, **kwargs):
|