Returns value decoded from DBMS specific hexadecimal representation >>> decodeDbmsHexValue('3132332031') == u'123 1' True >>> decodeDbmsHexValue('31003200330020003100') == u'123 1' True >>> decodeDbmsHexValue('00310032003300200031') == u'123 1' True >>> decodeDbmsHe
(value, raw=False)
| 4950 | return retVal |
| 4951 | |
| 4952 | def decodeDbmsHexValue(value, raw=False): |
| 4953 | """ |
| 4954 | Returns value decoded from DBMS specific hexadecimal representation |
| 4955 | |
| 4956 | >>> decodeDbmsHexValue('3132332031') == u'123 1' |
| 4957 | True |
| 4958 | >>> decodeDbmsHexValue('31003200330020003100') == u'123 1' |
| 4959 | True |
| 4960 | >>> decodeDbmsHexValue('00310032003300200031') == u'123 1' |
| 4961 | True |
| 4962 | >>> decodeDbmsHexValue('0x31003200330020003100') == u'123 1' |
| 4963 | True |
| 4964 | >>> decodeDbmsHexValue('313233203') == u'123 ?' |
| 4965 | True |
| 4966 | >>> decodeDbmsHexValue(['0x31', '0x32']) == [u'1', u'2'] |
| 4967 | True |
| 4968 | >>> decodeDbmsHexValue('5.1.41') == u'5.1.41' |
| 4969 | True |
| 4970 | """ |
| 4971 | |
| 4972 | retVal = value |
| 4973 | |
| 4974 | def _(value): |
| 4975 | retVal = value |
| 4976 | if value and isinstance(value, six.string_types): |
| 4977 | value = value.strip() |
| 4978 | |
| 4979 | if len(value) % 2 != 0: |
| 4980 | retVal = (decodeHex(value[:-1]) + b'?') if len(value) > 1 else value |
| 4981 | singleTimeWarnMessage("there was a problem decoding value '%s' from expected hexadecimal form" % value) |
| 4982 | else: |
| 4983 | retVal = decodeHex(value) |
| 4984 | |
| 4985 | if not raw: |
| 4986 | if not kb.binaryField: |
| 4987 | if Backend.isDbms(DBMS.MSSQL) and value.startswith("0x"): |
| 4988 | try: |
| 4989 | retVal = retVal.decode("utf-16-le") |
| 4990 | except UnicodeDecodeError: |
| 4991 | pass |
| 4992 | |
| 4993 | elif Backend.getIdentifiedDbms() in (DBMS.HSQLDB, DBMS.H2): |
| 4994 | try: |
| 4995 | retVal = retVal.decode("utf-16-be") |
| 4996 | except UnicodeDecodeError: |
| 4997 | pass |
| 4998 | |
| 4999 | if not isinstance(retVal, six.text_type): |
| 5000 | retVal = getUnicode(retVal, conf.encoding or UNICODE_ENCODING) |
| 5001 | |
| 5002 | if u"\x00" in retVal: |
| 5003 | retVal = retVal.replace(u"\x00", u"") |
| 5004 | |
| 5005 | return retVal |
| 5006 | |
| 5007 | try: |
| 5008 | retVal = applyFunctionRecursively(value, _) |
| 5009 | except: |
no test coverage detected
searching dependent graphs…