Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

1512f8cd-7a24-42f7-9b1c-f9fec9ddc257 2.2 KB
Raw

You have to be logged in to leave a comment. Sign In
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
  1. import os
  2. import platform
  3. import pathlib
  4. def _settings_root_XP():
  5. return os.path.join(os.environ['USERPROFILE'], 'Local Settings')
  6. def _settings_root_Vista():
  7. return os.environ.get('LOCALAPPDATA', os.environ.get('ProgramData', '.'))
  8. def _data_root_Windows():
  9. release, version, csd, ptype = platform.win32_ver()
  10. root = _settings_root_XP() if release == 'XP' else _settings_root_Vista()
  11. return pathlib.Path(root, 'Python Keyring')
  12. def _data_root_Linux():
  13. """
  14. Use freedesktop.org Base Dir Specification to determine storage
  15. location.
  16. """
  17. fallback = pathlib.Path.home() / '.local/share'
  18. root = os.environ.get('XDG_DATA_HOME', None) or fallback
  19. return pathlib.Path(root, 'python_keyring')
  20. _config_root_Windows = _data_root_Windows
  21. def _check_old_config_root():
  22. """
  23. Prior versions of keyring would search for the config
  24. in XDG_DATA_HOME, but should probably have been
  25. searching for config in XDG_CONFIG_HOME. If the
  26. config exists in the former but not in the latter,
  27. raise a RuntimeError to force the change.
  28. """
  29. # disable the check - once is enough and avoids infinite loop
  30. globals()['_check_old_config_root'] = lambda: None
  31. config_file_new = os.path.join(_config_root_Linux(), 'keyringrc.cfg')
  32. config_file_old = os.path.join(_data_root_Linux(), 'keyringrc.cfg')
  33. if os.path.isfile(config_file_old) and not os.path.isfile(config_file_new):
  34. msg = (
  35. "Keyring config exists only in the old location "
  36. f"{config_file_old} and should be moved to {config_file_new} "
  37. "to work with this version of keyring."
  38. )
  39. raise RuntimeError(msg)
  40. def _config_root_Linux():
  41. """
  42. Use freedesktop.org Base Dir Specification to determine config
  43. location.
  44. """
  45. _check_old_config_root()
  46. fallback = pathlib.Path.home() / '.config'
  47. key = 'XDG_CONFIG_HOME'
  48. root = os.environ.get(key, None) or fallback
  49. return pathlib.Path(root, 'python_keyring')
  50. # by default, use Unix convention
  51. data_root = globals().get('_data_root_' + platform.system(), _data_root_Linux)
  52. config_root = globals().get('_config_root_' + platform.system(), _config_root_Linux)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...