Example #1
0
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')>"
    )
Example #2
0
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')>"
    )
Example #3
0
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)
Example #4
0
def test_strip_non_printable_only_binary():
    assert strip_non_printable(ub(chr(20)) +
                               ub(chr(155))) == ('(contains binary)')
Example #5
0
def test_strip_non_printable_contains_binary():
    assert strip_non_printable(ub(chr(20)) + 'my thingo' +
                               ub(chr(155))) == ('my thingo (contains binary)')
Example #6
0
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')>")
Example #7
0
def test_strip_non_printable_only_binary():
    assert strip_non_printable(ub(chr(20)) + ub(chr(155))) == (
        '(contains binary)'
    )
Example #8
0
def test_strip_non_printable_contains_binary():
    assert strip_non_printable(ub(chr(20)) + 'my thingo' + ub(chr(155))) == (
        'my thingo (contains binary)'
    )