Below is the file 'goatpy/snmpwrapper.py' from this revision. You can also download the file.

#!/usr/bin/python

import sys
import re
from goatpy.utility import iter_command, run_command

snmp_line_re = re.compile(r'^([A-Za-z0-9\-:\.]+) = ([A-Za-z0-9\-]+): (.*)$')

def snmpwalk(hostname, community, version, oid=None, timeout=None):
	if version == "2c": base_command = "/usr/bin/snmpbulkwalk"
	else: base_command = "/usr/bin/snmpwalk"
	snmp_command = base_command + " -v %s -c %s %s %s" % (version, community, hostname, oid or ".iso")
	oid = None
	for line in iter_command(snmp_command, timeout):
		line = line.strip()
		match = snmp_line_re.match(line)
		if match:
			oid, type, value = match.groups()
			yield (oid.split('.'), type, value)

def snmpget(hostname, community, version, oid, timeout=None):
	base_command = "/usr/bin/snmpget"
	snmp_command = base_command + " -v %s -c %s %s %s" % (version, community, hostname, oid)
	result = run_command(snmp_command)
	if result.has_key('fromchild'):
		res = result['fromchild']
		lines = res.split("\r\n")
		if len(lines) > 0:
			match = snmp_line_re.match(lines[0])
			if match: lines[0] = match.groups()[2]
		res = "\n".join(lines)
		return res
	else: return ''