Generate a random string. Functions the same as :meth:`~RandomGen.randUniqueStr`, the only difference being that the generated string is NOT guaranteed to be unique.
(self, minStrLen=None, maxStrLen=None, charList=None, escapeChars="", noBOBL=True)
| 200 | return randStr |
| 201 | |
| 202 | def randGenStr(self, minStrLen=None, maxStrLen=None, charList=None, escapeChars="", noBOBL=True): |
| 203 | """ |
| 204 | Generate a random string. Functions the same as |
| 205 | :meth:`~RandomGen.randUniqueStr`, the only difference being |
| 206 | that the generated string is NOT guaranteed to be unique. |
| 207 | """ |
| 208 | minStrLen, maxStrLen = self._getSizes(minStrLen, maxStrLen) |
| 209 | |
| 210 | if charList is None: |
| 211 | charList = RandomGen._randStrCharList |
| 212 | |
| 213 | randStrLen = RandomGen.randGen.randint(minStrLen, maxStrLen) |
| 214 | randStr = "".join(self.randSelect(charList) for x in range(randStrLen)) |
| 215 | |
| 216 | if noBOBL: |
| 217 | while RandomGen._boblSyntaxRegex.search(randStr): |
| 218 | randStr = "".join(self.randSelect(charList) for x in range(randStrLen)) |
| 219 | |
| 220 | # escape 'escapeChars', making sure that an already escaped char isn't |
| 221 | # accidentally un-escaped by adding an extra '\' |
| 222 | for char in escapeChars: |
| 223 | randStr = re.sub(r"(?<!\\)(\\{2})*(?!\\)" + re.escape(char), "\g<1>\\" + char, randStr) |
| 224 | |
| 225 | return randStr |
| 226 | |
| 227 | def _getSizes(self, minLen, maxLen): |
| 228 | if minLen is None or maxLen is None: |
no test coverage detected