A uname_result that's largely compatible with a simple namedtuple except that 'processor' is resolved late and cached to avoid calling "uname" except when needed.
| 874 | ### Portable uname() interface |
| 875 | |
| 876 | class uname_result( |
| 877 | collections.namedtuple( |
| 878 | "uname_result_base", |
| 879 | "system node release version machine") |
| 880 | ): |
| 881 | """ |
| 882 | A uname_result that's largely compatible with a |
| 883 | simple namedtuple except that 'processor' is |
| 884 | resolved late and cached to avoid calling "uname" |
| 885 | except when needed. |
| 886 | """ |
| 887 | |
| 888 | _fields = ('system', 'node', 'release', 'version', 'machine', 'processor') |
| 889 | |
| 890 | @functools.cached_property |
| 891 | def processor(self): |
| 892 | return _unknown_as_blank(_Processor.get()) |
| 893 | |
| 894 | def __iter__(self): |
| 895 | return itertools.chain( |
| 896 | super().__iter__(), |
| 897 | (self.processor,) |
| 898 | ) |
| 899 | |
| 900 | @classmethod |
| 901 | def _make(cls, iterable): |
| 902 | # override factory to affect length check |
| 903 | num_fields = len(cls._fields) - 1 |
| 904 | result = cls.__new__(cls, *iterable) |
| 905 | if len(result) != num_fields + 1: |
| 906 | msg = f'Expected {num_fields} arguments, got {len(result)}' |
| 907 | raise TypeError(msg) |
| 908 | return result |
| 909 | |
| 910 | def __getitem__(self, key): |
| 911 | return tuple(self)[key] |
| 912 | |
| 913 | def __len__(self): |
| 914 | return len(tuple(iter(self))) |
| 915 | |
| 916 | def __reduce__(self): |
| 917 | return uname_result, tuple(self)[:len(self._fields) - 1] |
| 918 | |
| 919 | |
| 920 | _uname_cache = None |
no outgoing calls
no test coverage detected
searching dependent graphs…