Safe way how to get the proper exception represtation as a string >>> getSafeExString(SqlmapBaseException('foobar')) == 'foobar' True >>> getSafeExString(OSError(0, 'foobar')) == 'OSError: foobar' True
(ex, encoding=None)
| 5482 | yield target |
| 5483 | |
| 5484 | def getSafeExString(ex, encoding=None): |
| 5485 | """ |
| 5486 | Safe way how to get the proper exception represtation as a string |
| 5487 | |
| 5488 | >>> getSafeExString(SqlmapBaseException('foobar')) == 'foobar' |
| 5489 | True |
| 5490 | >>> getSafeExString(OSError(0, 'foobar')) == 'OSError: foobar' |
| 5491 | True |
| 5492 | """ |
| 5493 | |
| 5494 | retVal = None |
| 5495 | |
| 5496 | if getattr(ex, "message", None): |
| 5497 | retVal = ex.message |
| 5498 | elif getattr(ex, "msg", None): |
| 5499 | retVal = ex.msg |
| 5500 | elif getattr(ex, "args", None): |
| 5501 | for candidate in ex.args[::-1]: |
| 5502 | if isinstance(candidate, six.string_types): |
| 5503 | retVal = candidate |
| 5504 | break |
| 5505 | |
| 5506 | if retVal is None: |
| 5507 | retVal = str(ex) |
| 5508 | elif not isinstance(ex, SqlmapBaseException): |
| 5509 | retVal = "%s: %s" % (type(ex).__name__, retVal) |
| 5510 | |
| 5511 | return getUnicode(retVal or "", encoding=encoding).strip() |
| 5512 | |
| 5513 | def safeVariableNaming(value): |
| 5514 | """ |
no test coverage detected
searching dependent graphs…