def test_snmp_variable_repr_binary(): var = SNMPVariable( "sysDescr", "0", ub(chr(20)) + "my thingo" + ub(chr(155)), "OCTETSTR" ) assert var.__repr__() == ( "<SNMPVariable value='my thingo (contains binary)' " "(oid='sysDescr', oid_index='0', snmp_type='OCTETSTR')>" )
def test_snmp_variable_repr_binary_only(): var = SNMPVariable( 'sysDescr', '0', ub(chr(20)) + ub(chr(155)), 'OCTETSTR' ) assert var.__repr__() == ( "<SNMPVariable value='(contains binary)' " "(oid='sysDescr', oid_index='0', snmp_type='OCTETSTR')>" )
def tostr(value): """ Converts any variable to a string or returns None if the variable contained None to begin with; this function currently supports None, unicode strings, byte strings and numbers. :param value: the value you wish to convert to a string """ if value is None: return None elif isinstance(value, text_type): return value elif isinstance(value, (int, float)): return str(value) else: return ub(value)
def test_strip_non_printable_only_binary(): assert strip_non_printable(ub(chr(20)) + ub(chr(155))) == ('(contains binary)')
def test_strip_non_printable_contains_binary(): assert strip_non_printable(ub(chr(20)) + 'my thingo' + ub(chr(155))) == ('my thingo (contains binary)')
def test_snmp_variable_repr_binary_only(): var = SNMPVariable('sysDescr', '0', ub(chr(20)) + ub(chr(155)), 'OCTETSTR') assert var.__repr__() == ( "<SNMPVariable value='(contains binary)' " "(oid='sysDescr', oid_index='0', snmp_type='OCTETSTR')>")
def test_strip_non_printable_only_binary(): assert strip_non_printable(ub(chr(20)) + ub(chr(155))) == ( '(contains binary)' )
def test_strip_non_printable_contains_binary(): assert strip_non_printable(ub(chr(20)) + 'my thingo' + ub(chr(155))) == ( 'my thingo (contains binary)' )