01-arcadia.patch 4.0 KB

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