Commit 4fc94707 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(number_suffixed): Don't use "".startswith.

(isalpha): New function.  Use it instead of "".isalpha.
(isdigit): New function.  Use it instead of "".isdigit.
(prot_a_bitstring.check_implemented): Old Python versions cannot loop
	over a dictionary; add an explicit call to the .keys() method.
(lexer.__init__): Use string.strip instead of "".strip.
parent e1c1db98
......@@ -44,7 +44,7 @@ defined_fields = {
undefined_fields = {}
def number_suffixed(s, base):
if not s.startswith(base):
if s[:len(base)] != base:
return 0
s = s[len(base):]
if len(s) < 1:
......@@ -55,6 +55,18 @@ def number_suffixed(s, base):
except:
return 0
def isalpha(s):
for c in s:
if c not in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ":
return 0
return 1
def isdigit(s):
for c in s:
if c not in "0123456789":
return 0
return 1
class reader_eof(Exception):
pass
......@@ -137,7 +149,7 @@ class prot_a_bitstring(prot_a_type):
def check_implemented(self, name, implemented_fields):
res = []
i = {}
for f in implemented_fields:
for f in implemented_fields.keys():
if not self.__bits.has_key(f):
res.append("%s: bit ``%s'' not documented" % (name, f))
i[f] = None
......@@ -303,7 +315,7 @@ class lexer:
f = open("requests-numbered.tmp", "r")
for line in f.readlines():
[nr, name] = string.split(line, " ")
self.__implemented_reqs[name.strip()] = nr
self.__implemented_reqs[string.strip(name)] = nr
f.close()
self.__implemented_asyncs = {}
......@@ -311,7 +323,7 @@ class lexer:
f = open("asyncs-numbered.tmp", "r")
for line in f.readlines():
[nr, name] = string.split(line, " ")
name = name.strip()
name = string.strip(name)
if n.has_key(nr):
sys.stderr.write("../src/server/async.h:1:enum async:"
" number %s used for both %s and %s\n" % (
......@@ -327,7 +339,7 @@ class lexer:
for line in f.readlines():
[nr, name] = string.split(line, " ")
nr = int(nr)
name = name.strip()
name = string.strip(name)
if n.has_key(nr):
sys.stderr.write("../src/include/kom-types.h:1:enum info_type:"
" number %s used for both %s and %s\n" % (
......@@ -340,14 +352,14 @@ class lexer:
self.__implemented_conftypes = {}
f = open("conftypes.tmp", "r")
for line in f.readlines():
name = line.strip()
name = string.strip(line)
self.__implemented_conftypes[name] = nr
f.close()
self.__implemented_privbits = {}
f = open("privbits.tmp", "r")
for line in f.readlines():
name = line.strip()
name = string.strip(line)
self.__implemented_privbits[name] = nr
f.close()
......@@ -364,7 +376,7 @@ class lexer:
return
cmd = ""
while 1:
if c.isalpha() or c in '_"':
if isalpha(c) or c in '_"':
cmd = cmd + c
c = self.__reader.getc()
elif c in ' \t\n{@=-':
......@@ -1175,12 +1187,12 @@ class lexer:
c = self.__reader.getc()
while c.isspace():
c = self.__reader.getc()
if c.isalpha():
if isalpha(c):
res = c
while 1:
c = self.__reader.getc()
if not c.isalpha() and c not in "-" and not c.isdigit():
if c.isdigit():
if not isalpha(c) and c not in "-" and not isdigit(c):
if isdigit(c):
self.error(self.__reader.line_no(),
"bad token ``%s''" % (res + c))
self.__reader.ungetc(c)
......@@ -1206,12 +1218,12 @@ class lexer:
return c
else:
return c + d
elif c.isdigit():
elif isdigit(c):
res = c
while 1:
c = self.__reader.getc()
if not c.isdigit():
if c.isalpha():
if not isdigit(c):
if isalpha(c):
self.error(self.__reader.line_no(),
"bad token ``%s''" % (res + c))
self.__reader.ungetc(c)
......@@ -1233,7 +1245,7 @@ class lexer:
res = c
while 1:
c = self.__reader.getc()
if not c.isalpha():
if not isalpha(c):
self.__reader.ungetc(c)
return res
res = res + c
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment