@@ -70,7 +70,7 @@ def next(self):
7070 __next__ = next
7171
7272
73- class VolatileValue :
73+ class VolatileValue ( object ) :
7474 def __repr__ (self ):
7575 return "<%s>" % self .__class__ .__name__
7676 def __eq__ (self , other ):
@@ -266,41 +266,33 @@ def _fix(self):
266266 return random .choice (self ._choice )
267267
268268class RandString (RandField ):
269- def __init__ (self , size = None , chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" ):
269+ def __init__ (self , size = None , chars = b "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" ):
270270 if size is None :
271271 size = RandNumExpo (0.01 )
272272 self .size = size
273273 self .chars = chars
274274 def _fix (self ):
275- s = ""
275+ s = b ""
276276 for _ in range (self .size ):
277- s += random .choice (self .chars )
277+ s += chb ( random .choice (self .chars ) )
278278 return s
279+ def __str__ (self ):
280+ return plain_str (self ._fix ())
281+ def __bytes__ (self ):
282+ return raw (self ._fix ())
279283 def __mul__ (self , n ):
280284 return self ._fix ()* n
281285
282- class RandBin (RandString , object ):
286+ class RandBin (RandString ):
283287 def __init__ (self , size = None ):
284288 super (RandBin , self ).__init__ (size = size , chars = b"" .join (chb (c ) for c in range (256 )))
285- def _fix (self ):
286- s = b""
287- for _ in range (self .size ):
288- s += chb (random .choice (self .chars ))
289- return s
290-
291289
292- class RandTermString (RandString ):
290+ class RandTermString (RandBin ):
293291 def __init__ (self , size , term ):
294- RandString . __init__ ( self , size , "" . join ( map ( chr , range ( 1 , 256 ))) )
295- self . term = term
292+ self . term = raw ( term )
293+ super ( RandTermString , self ). __init__ ( size = size )
296294 def _fix (self ):
297- return RandString ._fix (self )+ self .term
298-
299- def __str__ (self ):
300- return str (self ._fix ())
301-
302- def __bytes__ (self ):
303- return raw (self ._fix ())
295+ return RandBin ._fix (self )+ self .term
304296
305297
306298class RandIP (RandString ):
0 commit comments