MCPcopy Index your code
hub / github.com/python/cpython / _RandomNameSequence

Class _RandomNameSequence

Lib/tempfile.py:133–155  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

131
132
133class _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
157def _candidate_tempdir_list():
158 """Generate a list of candidate temporary directories which

Callers 2

_get_default_tempdirFunction · 0.85
_get_candidate_namesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…