Download tasks/codeql_python_benchmark51_v2/pyvul-b5417e7c5b6909a4c5f9/patch.diff from Benchanything/checkerbench: direct link, hf CLI and curl.
- Browser
- Download file 2.78 kB
-
https://huggingface.co/datasets/Benchanything/checkerbench/resolve/main/tasks/codeql_python_benchmark51_v2/pyvul-b5417e7c5b6909a4c5f9/patch.diff
- Command line
-
hf download hf://datasets/Benchanything/checkerbench/tasks/codeql_python_benchmark51_v2/pyvul-b5417e7c5b6909a4c5f9/patch.diff
-
curl -L -o patch.diff https://huggingface.co/datasets/Benchanything/checkerbench/resolve/main/tasks/codeql_python_benchmark51_v2/pyvul-b5417e7c5b6909a4c5f9/patch.diff
2.78 kB
| diff --git a/rply/parsergenerator.py b/rply/parsergenerator.py | |
| index f2ed8ee..995f78e 100644 | |
| --- a/rply/parsergenerator.py | |
| +++ b/rply/parsergenerator.py | |
| import sys | |
| import tempfile | |
| import warnings | |
| +from appdirs import AppDirs | |
| + | |
| from rply.errors import ParserGeneratorError, ParserGeneratorWarning | |
| from rply.grammar import Grammar | |
| from rply.parser import LRParser | |
| class ParserGenerator(object): | |
| g.compute_first() | |
| g.compute_follow() | |
| - # win32 temp directories are already per-user | |
| - if os.name == "nt": | |
| - cache_file = os.path.join( | |
| - tempfile.gettempdir(), | |
| - "rply-%s-%s-%s.json" % ( | |
| - self.VERSION, self.cache_id, self.compute_grammar_hash(g) | |
| - ) | |
| - ) | |
| - else: | |
| - cache_file = os.path.join( | |
| - tempfile.gettempdir(), | |
| - "rply-%s-%s-%s-%s.json" % ( | |
| - self.VERSION, | |
| - os.getuid(), | |
| - self.cache_id, | |
| - self.compute_grammar_hash(g) | |
| - ) | |
| + cache_dir = AppDirs("rply").user_cache_dir | |
| + cache_file = os.path.join( | |
| + cache_dir, | |
| + "rply-%s-%s-%s.json" % ( | |
| + self.VERSION, self.cache_id, self.compute_grammar_hash(g) | |
| ) | |
| + ) | |
| + | |
| table = None | |
| if os.path.exists(cache_file): | |
| with open(cache_file) as f: | |
| data = json.load(f) | |
| - stat_result = os.fstat(f.fileno()) | |
| - if ( | |
| - os.name == "nt" or ( | |
| - stat_result.st_uid == os.getuid() and | |
| - stat.S_IMODE(stat_result.st_mode) == 0o0600 | |
| - ) | |
| - ): | |
| - if self.data_is_valid(g, data): | |
| - table = LRTable.from_cache(g, data) | |
| + if self.data_is_valid(g, data): | |
| + table = LRTable.from_cache(g, data) | |
| if table is None: | |
| table = LRTable.from_grammar(g) | |
| - fd = os.open( | |
| - cache_file, os.O_RDWR | os.O_CREAT | os.O_EXCL, 0o0600 | |
| - ) | |
| - with os.fdopen(fd, "w") as f: | |
| + if not os.path.exists(cache_dir): | |
| + os.makedirs(cache_dir) | |
| + | |
| + with open(cache_file, "w") as f: | |
| json.dump(self.serialize_table(table), f) | |
| + | |
| if table.sr_conflicts: | |
| warnings.warn( | |
| "%d shift/reduce conflict%s" % ( | |
| diff --git a/setup.py b/setup.py | |
| index df6af7e..1072f5e 100644 | |
| --- a/setup.py | |
| +++ b/setup.py | |
| setup( | |
| author="Alex Gaynor", | |
| author_email="alex.gaynor@gmail.com", | |
| packages=["rply"], | |
| + install_requires=["appdirs"], | |
| ) | |