MCPcopy Create free account
hub / github.com/Bashfuscator/Bashfuscator / randGenStr

Method randGenStr

bashfuscator/core/engine/random.py:202–225  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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:

Callers 5

randGenVarMethod · 0.95
randUniqueStrMethod · 0.95
genXorKeyMethod · 0.80
mutateMethod · 0.80
_getRandCharsMethod · 0.80

Calls 2

_getSizesMethod · 0.95
randSelectMethod · 0.95

Tested by

no test coverage detected