

def varbind_pretty_value(varbind):
    output = varbind.value
    objid = ObjectId(varbind.oid)
    if (varbind.value_type == 'ipaddress'):
        try:
            name = socket.gethostbyaddr(varbind.value)[0]
            output = ('%s (%s)' % (name, output))
        except socket.error:
            pass
    elif (varbind.value_type == 'oid'):
        output = to_mibname(varbind.value)
    elif (varbind.value_type == 'octet'):
        if (objid.textual == 'DateAndTime'):
            output = decode_date(varbind.value)
    if (objid.enums and varbind.value.isdigit()):
        val = int(varbind.value)
        output = objid.enums.get(val, val)
    if objid.units:
        output = ('%s %s' % (output, objid.units))
    return output

dataset/ETHPy150Open dropbox/trapperkeeper/trapperkeeper/utils.py varbind_pretty_value/original