01-arcadia.patch 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. --- contrib/python/parso/py2/parso/cache.py (working tree)
  2. +++ contrib/python/parso/py2/parso/cache.py (index)
  3. @@ -142,6 +142,8 @@
  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. try:
  10. if p_time > os.path.getmtime(cache_path):
  11. # Cache is outdated
  12. --- contrib/python/parso/py2/parso/file_io.py (working tree)
  13. +++ contrib/python/parso/py2/parso/file_io.py (index)
  14. @@ -1,6 +1,8 @@
  15. import os
  16. from parso._compatibility import FileNotFoundError
  17. +import __res as res
  18. +
  19. class FileIO(object):
  20. def __init__(self, path):
  21. @@ -10,6 +12,9 @@
  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/py2/parso/grammar.py (working tree)
  31. +++ contrib/python/parso/py2/parso/grammar.py (index)
  32. @@ -1,5 +1,7 @@
  33. import hashlib
  34. import os
  35. +import sys
  36. +import pkgutil
  37. from parso._compatibility import FileNotFoundError, is_pypy
  38. from parso.pgen2 import generate_grammar
  39. @@ -246,12 +248,15 @@
  40. return _loaded_grammars[path]
  41. except KeyError:
  42. try:
  43. + bnf_text = pkgutil.get_data("parso", file)
  44. + if bnf_text is None:
  45. + raise FileNotFoundError
  46. + if sys.version_info[0] == 3:
  47. + bnf_text = bnf_text.decode("ascii")
  48. - with open(path) as f:
  49. - bnf_text = f.read()
  50. grammar = PythonGrammar(version_info, bnf_text)
  51. return _loaded_grammars.setdefault(path, grammar)
  52. + except (FileNotFoundError, IOError):
  53. - except FileNotFoundError:
  54. message = "Python version %s.%s is currently not supported." % (version_info.major, version_info.minor)
  55. raise NotImplementedError(message)
  56. else:
  57. --- contrib/python/parso/py2/tests/conftest.py (working tree)
  58. +++ contrib/python/parso/py2/tests/conftest.py (index)
  59. @@ -6,6 +6,7 @@
  60. import os
  61. import pytest
  62. +import yatest.common
  63. import parso
  64. from parso import cache
  65. @@ -43,7 +44,7 @@
  66. def pytest_generate_tests(metafunc):
  67. if 'normalizer_issue_case' in metafunc.fixturenames:
  68. + base_dir = os.path.join(yatest.common.test_source_path(), 'normalizer_issue_files')
  69. - base_dir = os.path.join(os.path.dirname(__file__), 'test', 'normalizer_issue_files')
  70. cases = list(colllect_normalizer_tests(base_dir))
  71. metafunc.parametrize(
  72. --- contrib/python/parso/py2/tests/test_cache.py (working tree)
  73. +++ contrib/python/parso/py2/tests/test_cache.py (index)
  74. @@ -36,6 +36,7 @@
  75. return cache_path
  76. +@pytest.mark.skip("SUBBOTNIK-2721 Disable load cache from disk")
  77. def test_modulepickling_change_cache_dir(tmpdir):
  78. """
  79. ParserPickling should not save old cache when cache_directory is changed.
  80. @@ -101,6 +102,7 @@
  81. assert cached2 is None
  82. +@pytest.mark.skip
  83. def test_cache_limit():
  84. def cache_size():
  85. return sum(len(v) for v in parser_cache.values())
  86. @@ -131,6 +133,7 @@
  87. return self._last_modified
  88. +@pytest.mark.skip
  89. @pytest.mark.parametrize('diff_cache', [False, True])
  90. @pytest.mark.parametrize('use_file_io', [False, True])
  91. def test_cache_last_used_update(diff_cache, use_file_io):
  92. @@ -177,6 +180,7 @@
  93. assert not old_paths.intersection(os.listdir(raw_cache_path))
  94. +@pytest.mark.skip
  95. @skip_pypy
  96. def test_permission_error(monkeypatch):
  97. def save(*args, **kwargs):