aboutsummaryrefslogtreecommitdiff
path: root/pow/POW-0.7/cfgparse.py
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2007-08-02 01:26:22 +0000
committerRob Austein <sra@hactrn.net>2007-08-02 01:26:22 +0000
commitdfbd879eb471809dd58b449e1fe63b5c7a2c9ee4 (patch)
tree18248550e9d11e8f15c6f9d58b511bc8c8253392 /pow/POW-0.7/cfgparse.py
parenteab07d8a5c316d30cc989b77a03e4ca3aaeaaf39 (diff)
Parsing the OID field is a bit more work but more reliable than
expecting a valid OID in the Description field. svn path=/pow/POW-0.7/cfgparse.py; revision=816
Diffstat (limited to 'pow/POW-0.7/cfgparse.py')
-rwxr-xr-xpow/POW-0.7/cfgparse.py22
1 files changed, 20 insertions, 2 deletions
diff --git a/pow/POW-0.7/cfgparse.py b/pow/POW-0.7/cfgparse.py
index d3de41b8..d1122bba 100755
--- a/pow/POW-0.7/cfgparse.py
+++ b/pow/POW-0.7/cfgparse.py
@@ -36,6 +36,21 @@
import string, re, types, pprint
+def decodeOid(val):
+ val = [int(val,16) for val in val.split(" ")][2:]
+ arc12 = val[0]
+ arc1, arc2 = divmod(arc12, 40)
+ oids = [arc1,arc2]
+ total = 0
+ for byte in val[1:]:
+ if byte & 0x80:
+ total = (total << 7) | (byte ^ 0x80)
+ else:
+ total = (total << 7) | byte
+ oids.append(total)
+ total = 0
+ return tuple(oids)
+
# for people out there who, like me, hate regexs(too easy to make mistakes
# with) I apologise profusely!
@@ -58,6 +73,7 @@ class Parser:
m = self.oidMatch.match( line )
if m:
dict['hexoid'] = m.group(1)
+ dict['oid'] = decodeOid(m.group(1))
return 0
else:
m = self.commentMatch.match( line )
@@ -69,8 +85,10 @@ class Parser:
if m:
dict['description'] = m.group(1)
n = self.oidNameMatch.match( m.group(1) )
- dict['name'] = string.strip( n.group(1) )
- dict['oid'] = tuple( map(int, string.split( n.group(2), ' ') ) )
+ if n:
+ dict['name'] = string.strip( n.group(1) )
+ else:
+ dict['name'] = m.group(1)
return 0
else:
m = self.warningMatch.match( line )