Return a volatile object whose value is both random and suitable for this field
(self)
| 284 | return copy.copy(self) |
| 285 | |
| 286 | def randval(self): |
| 287 | # type: () -> VolatileValue[Any] |
| 288 | """Return a volatile object whose value is both random and suitable for this field""" # noqa: E501 |
| 289 | fmtt = self.fmt[-1] |
| 290 | if fmtt in "BbHhIiQq": |
| 291 | return {"B": RandByte, "b": RandSByte, |
| 292 | "H": RandShort, "h": RandSShort, |
| 293 | "I": RandInt, "i": RandSInt, |
| 294 | "Q": RandLong, "q": RandSLong}[fmtt]() |
| 295 | elif fmtt == "s": |
| 296 | if self.fmt[0] in "0123456789": |
| 297 | value = int(self.fmt[:-1]) |
| 298 | else: |
| 299 | value = int(self.fmt[1:-1]) |
| 300 | return RandBin(value) |
| 301 | else: |
| 302 | raise ValueError( |
| 303 | "no random class for [%s] (fmt=%s)." % ( |
| 304 | self.name, self.fmt |
| 305 | ) |
| 306 | ) |
| 307 | |
| 308 | |
| 309 | class _FieldContainer(object): |