An instance of _RandomNameSequence generates an endless sequence of unpredictable strings which can safely be incorporated into file names. Each string is eight characters long. Multiple threads can safely use the same instance at the same time. _RandomNameSequence is an iterator.
| 131 | |
| 132 | |
| 133 | class _RandomNameSequence: |
| 134 | """An instance of _RandomNameSequence generates an endless |
| 135 | sequence of unpredictable strings which can safely be incorporated |
| 136 | into file names. Each string is eight characters long. Multiple |
| 137 | threads can safely use the same instance at the same time. |
| 138 | |
| 139 | _RandomNameSequence is an iterator.""" |
| 140 | |
| 141 | characters = "abcdefghijklmnopqrstuvwxyz0123456789_" |
| 142 | |
| 143 | @property |
| 144 | def rng(self): |
| 145 | cur_pid = _os.getpid() |
| 146 | if cur_pid != getattr(self, '_rng_pid', None): |
| 147 | self._rng = _Random() |
| 148 | self._rng_pid = cur_pid |
| 149 | return self._rng |
| 150 | |
| 151 | def __iter__(self): |
| 152 | return self |
| 153 | |
| 154 | def __next__(self): |
| 155 | return ''.join(self.rng.choices(self.characters, k=8)) |
| 156 | |
| 157 | def _candidate_tempdir_list(): |
| 158 | """Generate a list of candidate temporary directories which |
no outgoing calls
no test coverage detected
searching dependent graphs…