mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-16 15:56:15 -04:00
Raise RpcGenError in event_rpcgen.py; from jmanison and Zack Weinberg
svn:r1333
This commit is contained in:
parent
342ad3550b
commit
37d3e16ce9
@ -36,6 +36,7 @@ Changes in 2.0.2-alpha:
|
|||||||
o Activate fd events in a pseudorandom order with O(N) backends, so that we don't systematically favor low fds (select) or earlier-added fds (poll, win32).
|
o Activate fd events in a pseudorandom order with O(N) backends, so that we don't systematically favor low fds (select) or earlier-added fds (poll, win32).
|
||||||
o Replace some read()/write() instances with send()/recv() to work properly on win32.
|
o Replace some read()/write() instances with send()/recv() to work properly on win32.
|
||||||
o Set truncated flag correctly in evdns server replies.
|
o Set truncated flag correctly in evdns server replies.
|
||||||
|
o Raise RpcGenError in event_rpcgen.py; from jmanison and Zack Weinberg
|
||||||
|
|
||||||
|
|
||||||
Changes in 2.0.1-alpha:
|
Changes in 2.0.1-alpha:
|
||||||
|
@ -24,6 +24,13 @@ cppdirect = []
|
|||||||
def TranslateList(mylist, mydict):
|
def TranslateList(mylist, mydict):
|
||||||
return map(lambda x: x % mydict, mylist)
|
return map(lambda x: x % mydict, mylist)
|
||||||
|
|
||||||
|
# Exception class for parse errors
|
||||||
|
class RpcGenError(Exception):
|
||||||
|
def __init__(self, why):
|
||||||
|
self.why = why
|
||||||
|
def __str__(self):
|
||||||
|
return str(self.why)
|
||||||
|
|
||||||
# Holds everything that makes a struct
|
# Holds everything that makes a struct
|
||||||
class Struct:
|
class Struct:
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
@ -34,11 +41,10 @@ class Struct:
|
|||||||
|
|
||||||
def AddEntry(self, entry):
|
def AddEntry(self, entry):
|
||||||
if self._tags.has_key(entry.Tag()):
|
if self._tags.has_key(entry.Tag()):
|
||||||
print >>sys.stderr, ( 'Entry "%s" duplicates tag number '
|
raise RpcGenError(
|
||||||
'%d from "%s" around line %d' ) % (
|
'Entry "%s" duplicates tag number %d from "%s" '
|
||||||
entry.Name(), entry.Tag(),
|
'around line %d' % (entry.Name(), entry.Tag(),
|
||||||
self._tags[entry.Tag()], line_count)
|
self._tags[entry.Tag()], line_count))
|
||||||
sys.exit(1)
|
|
||||||
self._entries.append(entry)
|
self._entries.append(entry)
|
||||||
self._tags[entry.Tag()] = entry.Name()
|
self._tags[entry.Tag()] = entry.Name()
|
||||||
print >>sys.stderr, ' Added entry: %s' % entry.Name()
|
print >>sys.stderr, ' Added entry: %s' % entry.Name()
|
||||||
@ -367,20 +373,17 @@ class Entry:
|
|||||||
|
|
||||||
def Verify(self):
|
def Verify(self):
|
||||||
if self.Array() and not self._can_be_array:
|
if self.Array() and not self._can_be_array:
|
||||||
print >>sys.stderr, (
|
raise RpcGenError(
|
||||||
'Entry "%s" cannot be created as an array '
|
'Entry "%s" cannot be created as an array '
|
||||||
'around line %d' ) % (self._name, self.LineCount())
|
'around line %d' % (self._name, self.LineCount()))
|
||||||
sys.exit(1)
|
|
||||||
if not self._struct:
|
if not self._struct:
|
||||||
print >>sys.stderr, (
|
raise RpcGenError(
|
||||||
'Entry "%s" does not know which struct it belongs to '
|
'Entry "%s" does not know which struct it belongs to '
|
||||||
'around line %d' ) % (self._name, self.LineCount())
|
'around line %d' % (self._name, self.LineCount()))
|
||||||
sys.exit(1)
|
|
||||||
if self._optional and self._array:
|
if self._optional and self._array:
|
||||||
print >>sys.stderr, ( 'Entry "%s" has illegal combination of '
|
raise RpcGenError(
|
||||||
'optional and array around line %d' ) % (
|
'Entry "%s" has illegal combination of optional and array '
|
||||||
self._name, self.LineCount() )
|
'around line %d' % (self._name, self.LineCount()))
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
def GetTranslation(self, extradict = {}):
|
def GetTranslation(self, extradict = {}):
|
||||||
mapping = {
|
mapping = {
|
||||||
@ -568,9 +571,9 @@ class EntryBytes(Entry):
|
|||||||
|
|
||||||
def Verify(self):
|
def Verify(self):
|
||||||
if not self._length:
|
if not self._length:
|
||||||
print >>sys.stderr, 'Entry "%s" needs a length around line %d' % (
|
raise RpcGenError(
|
||||||
self._name, self.LineCount() )
|
'Entry "%s" needs a length '
|
||||||
sys.exit(1)
|
'around line %d' % (self._name, self.LineCount()))
|
||||||
|
|
||||||
Entry.Verify(self)
|
Entry.Verify(self)
|
||||||
|
|
||||||
@ -1306,9 +1309,9 @@ def ProcessOneEntry(factory, newstruct, entry):
|
|||||||
if not name:
|
if not name:
|
||||||
res = re.match(r'^([^\[\]]+)(\[.*\])?$', token)
|
res = re.match(r'^([^\[\]]+)(\[.*\])?$', token)
|
||||||
if not res:
|
if not res:
|
||||||
print >>sys.stderr, 'Cannot parse name: \"%s\" around %d' % (
|
raise RpcGenError(
|
||||||
entry, line_count)
|
'Cannot parse name: \"%s\" '
|
||||||
sys.exit(1)
|
'around line %d' % (entry, line_count))
|
||||||
name = res.group(1)
|
name = res.group(1)
|
||||||
fixed_length = res.group(2)
|
fixed_length = res.group(2)
|
||||||
if fixed_length:
|
if fixed_length:
|
||||||
@ -1318,25 +1321,21 @@ def ProcessOneEntry(factory, newstruct, entry):
|
|||||||
if not separator:
|
if not separator:
|
||||||
separator = token
|
separator = token
|
||||||
if separator != '=':
|
if separator != '=':
|
||||||
print >>sys.stderr, 'Expected "=" after name \"%s\" got %s' % (
|
raise RpcGenError('Expected "=" after name \"%s\" got %s'
|
||||||
name, token)
|
% (name, token))
|
||||||
sys.exit(1)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not tag_set:
|
if not tag_set:
|
||||||
tag_set = 1
|
tag_set = 1
|
||||||
if not re.match(r'^(0x)?[0-9]+$', token):
|
if not re.match(r'^(0x)?[0-9]+$', token):
|
||||||
print >>sys.stderr, 'Expected tag number: \"%s\"' % entry
|
raise RpcGenError('Expected tag number: \"%s\"' % entry)
|
||||||
sys.exit(1)
|
|
||||||
tag = int(token, 0)
|
tag = int(token, 0)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
print >>sys.stderr, 'Cannot parse \"%s\"' % entry
|
raise RpcGenError('Cannot parse \"%s\"' % entry)
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
if not tag_set:
|
if not tag_set:
|
||||||
print >>sys.stderr, 'Need tag number: \"%s\"' % entry
|
raise RpcGenError('Need tag number: \"%s\"' % entry)
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
# Create the right entry
|
# Create the right entry
|
||||||
if entry_type == 'bytes':
|
if entry_type == 'bytes':
|
||||||
@ -1357,8 +1356,7 @@ def ProcessOneEntry(factory, newstruct, entry):
|
|||||||
# References another struct defined in our file
|
# References another struct defined in our file
|
||||||
newentry = factory.EntryStruct(entry_type, name, tag, res.group(1))
|
newentry = factory.EntryStruct(entry_type, name, tag, res.group(1))
|
||||||
else:
|
else:
|
||||||
print >>sys.stderr, 'Bad type: "%s" in "%s"' % (entry_type, entry)
|
raise RpcGenError('Bad type: "%s" in "%s"' % (entry_type, entry))
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
structs = []
|
structs = []
|
||||||
|
|
||||||
@ -1459,9 +1457,8 @@ def GetNextStruct(file):
|
|||||||
|
|
||||||
if not re.match(r'^struct %s {$' % _STRUCT_RE,
|
if not re.match(r'^struct %s {$' % _STRUCT_RE,
|
||||||
line, re.IGNORECASE):
|
line, re.IGNORECASE):
|
||||||
print >>sys.stderr, 'Missing struct on line %d: %s' % (
|
raise RpcGenError('Missing struct on line %d: %s'
|
||||||
line_count, line)
|
% (line_count, line))
|
||||||
sys.exit(1)
|
|
||||||
else:
|
else:
|
||||||
got_struct = 1
|
got_struct = 1
|
||||||
data += line
|
data += line
|
||||||
@ -1474,9 +1471,8 @@ def GetNextStruct(file):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
if len(tokens[1]):
|
if len(tokens[1]):
|
||||||
print >>sys.stderr, 'Trailing garbage after struct on line %d' % (
|
raise RpcGenError('Trailing garbage after struct on line %d'
|
||||||
line_count )
|
% line_count)
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
# We found the end of the struct
|
# We found the end of the struct
|
||||||
data += ' %s}' % tokens[0]
|
data += ' %s}' % tokens[0]
|
||||||
@ -1609,8 +1605,7 @@ class CCodeGenerator:
|
|||||||
def Generate(factory, filename):
|
def Generate(factory, filename):
|
||||||
ext = filename.split('.')[-1]
|
ext = filename.split('.')[-1]
|
||||||
if ext != 'rpc':
|
if ext != 'rpc':
|
||||||
print >>sys.stderr, 'Unrecognized file extension: %s' % ext
|
raise RpcGenError('Unrecognized file extension: %s' % ext)
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
print >>sys.stderr, 'Reading \"%s\"' % filename
|
print >>sys.stderr, 'Reading \"%s\"' % filename
|
||||||
|
|
||||||
@ -1644,12 +1639,14 @@ def Generate(factory, filename):
|
|||||||
entry.PrintCode(impl_fp)
|
entry.PrintCode(impl_fp)
|
||||||
impl_fp.close()
|
impl_fp.close()
|
||||||
|
|
||||||
def main(argv):
|
if __name__ == '__main__':
|
||||||
if len(argv) < 2 or not argv[1]:
|
try:
|
||||||
print >>sys.stderr, 'Need RPC description file as first argument.'
|
if len(sys.argv) < 2 or not sys.argv[1]:
|
||||||
|
raise RpcGenError('Need RPC description file as first argument.')
|
||||||
|
|
||||||
|
Generate(CCodeGenerator(), sys.argv[1])
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
except RpcGenError, e:
|
||||||
|
print >>sys.stderr, e
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
Generate(CCodeGenerator(), argv[1])
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main(sys.argv)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user