specitems 1.7.4__tar.gz → 1.7.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. {specitems-1.7.4 → specitems-1.7.5}/PKG-INFO +1 -1
  2. {specitems-1.7.4 → specitems-1.7.5}/pyproject.toml +1 -1
  3. {specitems-1.7.4 → specitems-1.7.5}/src/specitems/items.py +19 -8
  4. {specitems-1.7.4 → specitems-1.7.5}/README.md +0 -0
  5. {specitems-1.7.4 → specitems-1.7.5}/src/specitems/__init__.py +0 -0
  6. {specitems-1.7.4 → specitems-1.7.5}/src/specitems/cite.py +0 -0
  7. {specitems-1.7.4 → specitems-1.7.5}/src/specitems/clangformat.py +0 -0
  8. {specitems-1.7.4 → specitems-1.7.5}/src/specitems/clihash.py +0 -0
  9. {specitems-1.7.4 → specitems-1.7.5}/src/specitems/clipickle.py +0 -0
  10. {specitems-1.7.4 → specitems-1.7.5}/src/specitems/clispecdoc.py +0 -0
  11. {specitems-1.7.4 → specitems-1.7.5}/src/specitems/clitypeview.py +0 -0
  12. {specitems-1.7.4 → specitems-1.7.5}/src/specitems/cliutil.py +0 -0
  13. {specitems-1.7.4 → specitems-1.7.5}/src/specitems/cliverify.py +0 -0
  14. {specitems-1.7.4 → specitems-1.7.5}/src/specitems/cliyamlquery.py +0 -0
  15. {specitems-1.7.4 → specitems-1.7.5}/src/specitems/content.py +0 -0
  16. {specitems-1.7.4 → specitems-1.7.5}/src/specitems/contentcommonmark.py +0 -0
  17. {specitems-1.7.4 → specitems-1.7.5}/src/specitems/contentmarkdown.py +0 -0
  18. {specitems-1.7.4 → specitems-1.7.5}/src/specitems/contentsphinx.py +0 -0
  19. {specitems-1.7.4 → specitems-1.7.5}/src/specitems/contenttext.py +0 -0
  20. {specitems-1.7.4 → specitems-1.7.5}/src/specitems/copyrights.py +0 -0
  21. {specitems-1.7.4 → specitems-1.7.5}/src/specitems/getvaluesubprocess.py +0 -0
  22. {specitems-1.7.4 → specitems-1.7.5}/src/specitems/glossary.py +0 -0
  23. {specitems-1.7.4 → specitems-1.7.5}/src/specitems/hashutil.py +0 -0
  24. {specitems-1.7.4 → specitems-1.7.5}/src/specitems/itemmapper.py +0 -0
  25. {specitems-1.7.4 → specitems-1.7.5}/src/specitems/licenseinfo.py +0 -0
  26. {specitems-1.7.4 → specitems-1.7.5}/src/specitems/py.typed +0 -0
  27. {specitems-1.7.4 → specitems-1.7.5}/src/specitems/spdx.py +0 -0
  28. {specitems-1.7.4 → specitems-1.7.5}/src/specitems/spec.pickle +0 -0
  29. {specitems-1.7.4 → specitems-1.7.5}/src/specitems/specconfig.py +0 -0
  30. {specitems-1.7.4 → specitems-1.7.5}/src/specitems/specdoc.py +0 -0
  31. {specitems-1.7.4 → specitems-1.7.5}/src/specitems/specformatter.py +0 -0
  32. {specitems-1.7.4 → specitems-1.7.5}/src/specitems/specverify.py +0 -0
  33. {specitems-1.7.4 → specitems-1.7.5}/src/specitems/subprocessaction.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: specitems
3
- Version: 1.7.4
3
+ Version: 1.7.5
4
4
  Summary: Provides interfaces to work with specification items.
5
5
  Keywords: certification,documentation,markdown,qualification,requirements-management,traceability
6
6
  Author: The specitems Authors
@@ -4,7 +4,7 @@
4
4
 
5
5
  [project]
6
6
  name = "specitems"
7
- version = "1.7.4"
7
+ version = "1.7.5"
8
8
  description = "Provides interfaces to work with specification items."
9
9
  authors = [
10
10
  {name = "The specitems Authors", email = "specthings@embedded-brains.de"}
@@ -37,8 +37,8 @@ import logging
37
37
  import os
38
38
  import pickle
39
39
  import re
40
+ import secrets
40
41
  import stat
41
- import tempfile
42
42
  from typing import (Any, Callable, Collection, Iterable, Iterator, Match,
43
43
  Optional, Union)
44
44
  import json
@@ -753,6 +753,18 @@ def _json_load_data_by_uid(data_by_uid: ItemDataByUID, _cache_dir: str,
753
753
  path_2)
754
754
 
755
755
 
756
+ def _create_temporary_file(directory: str, suffix: str) -> tuple[int, str]:
757
+ while True:
758
+ path = os.path.join(directory, f".tmp-{secrets.token_hex(8)}{suffix}")
759
+ try:
760
+ # The umask applies to this mode, as for a file which open()
761
+ # creates.
762
+ return os.open(path, os.O_WRONLY | os.O_CREAT | os.O_EXCL,
763
+ 0o666), path
764
+ except FileExistsError:
765
+ continue
766
+
767
+
756
768
  def atomic_dump_to_file(path: str, data: Any,
757
769
  dumper: Callable[[Any], str | bytes]) -> None:
758
770
  """
@@ -765,6 +777,9 @@ def atomic_dump_to_file(path: str, data: Any,
765
777
  as the path. The temporary file is then renamed to the path. This way, a
766
778
  failure while producing the content cannot truncate or corrupt an already
767
779
  existing file at the path.
780
+
781
+ A file which exists keeps its permissions. A new file gets the
782
+ permissions which the umask leaves of 0o666.
768
783
  """
769
784
  dumped = dumper(data)
770
785
  encoding: Optional[str] = None
@@ -776,13 +791,9 @@ def atomic_dump_to_file(path: str, data: Any,
776
791
  directory = os.path.dirname(os.path.abspath(path))
777
792
  tmp_path: Optional[str] = None
778
793
  try:
779
- with tempfile.NamedTemporaryFile(mode=mode,
780
- encoding=encoding,
781
- dir=directory,
782
- prefix=".tmp-",
783
- suffix=os.path.basename(path),
784
- delete=False) as out:
785
- tmp_path = out.name
794
+ fd, tmp_path = _create_temporary_file(directory,
795
+ os.path.basename(path))
796
+ with os.fdopen(fd, mode, encoding=encoding) as out:
786
797
  with suppress(OSError):
787
798
  os.chmod(tmp_path, stat.S_IMODE(os.stat(path).st_mode))
788
799
  out.write(dumped)
File without changes