Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(415)

Unified Diff: ppapi/generators/idl_propertynode.py

Issue 98803004: Pepper: Clean up IDLNode internals. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix potential KeyError Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ppapi/generators/idl_node.py ('k') | tools/json_schema_compiler/idl_schema.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/generators/idl_propertynode.py
diff --git a/ppapi/generators/idl_propertynode.py b/ppapi/generators/idl_propertynode.py
index 33837a3cefa98f90a94249fbb15ded53fefe85df..e15354ad0a4d78be2cb6782ae3507f5cb87356ec 100755
--- a/ppapi/generators/idl_propertynode.py
+++ b/ppapi/generators/idl_propertynode.py
@@ -8,7 +8,6 @@ import re
import sys
from idl_log import ErrOut, InfoOut, WarnOut
-from idl_option import GetOption, Option, ParseOptions
#
# IDLPropertyNode
@@ -22,11 +21,6 @@ class IDLPropertyNode(object):
self.parents = []
self.property_map = {}
- def Error(self, msg):
- name = self.GetProperty('NAME', 'Unknown')
- parents = [parent.GetProperty('NAME', '???') for parent in self.parents]
- ErrOut.Log('%s [%s] : %s' % (name, ' '.join(parents), msg))
-
def AddParent(self, parent):
assert parent
self.parents.append(parent)
@@ -34,56 +28,26 @@ class IDLPropertyNode(object):
def SetProperty(self, name, val):
self.property_map[name] = val
- def _GetProperty_(self, name):
+ def GetProperty(self, name):
# Check locally for the property, and return it if found.
prop = self.property_map.get(name, None)
- if prop is not None: return prop
+ if prop is not None:
+ return prop
# If not, seach parents in order
for parent in self.parents:
prop = parent.GetProperty(name)
- if prop is not None: return prop
+ if prop is not None:
+ return prop
# Otherwise, it can not be found.
return None
- def GetProperty(self, name, default=None):
- prop = self._GetProperty_(name)
- if prop is None:
- return default
- else:
- return prop
-
- def GetPropertyLocal(self, name, default=None):
- # Search for the property, but only locally, returning the
- # default if not found.
- prop = self.property_map.get(name, default)
- return prop
-
- # Regular expression to parse property keys in a string such that a string
- # "My string $NAME$" will find the key "NAME".
- regex_var = re.compile('(?P<src>[^\\$]+)|(?P<key>\\$\\w+\\$)')
+ def GetPropertyLocal(self, name):
+ # Search for the property, but only locally.
+ return self.property_map.get(name, None)
def GetPropertyList(self):
return self.property_map.keys()
- # Recursively expands text keys in the form of $KEY$ with the value
- # of the property of the same name. Since this is done recursively
- # one property can be defined in terms of another.
- def Replace(self, text):
- itr = IDLPropertyNode.regex_var.finditer(text)
- out = ''
- for m in itr:
- (start, stop) = m.span()
- if m.lastgroup == 'src':
- out += text[start:stop]
- if m.lastgroup == 'key':
- key = text[start+1:stop-1]
- val = self.GetProperty(key, None)
- if not val:
- self.Error('No property "%s"' % key)
- out += self.Replace(str(val))
- return out
-
-
#
# Testing functions
#
@@ -91,16 +55,18 @@ class IDLPropertyNode(object):
# Build a property node, setting the properties including a name, and
# associate the children with this new node.
#
-def BuildNode(name, props, children=[], parents=[]):
+def BuildNode(name, props, children=None, parents=None):
node = IDLPropertyNode()
node.SetProperty('NAME', name)
for prop in props:
toks = prop.split('=')
node.SetProperty(toks[0], toks[1])
- for child in children:
- child.AddParent(node)
- for parent in parents:
- node.AddParent(parent)
+ if children:
+ for child in children:
+ child.AddParent(node)
+ if parents:
+ for parent in parents:
+ node.AddParent(parent)
return node
def ExpectProp(node, name, val):
@@ -128,63 +94,14 @@ def PropertyTest():
errors += ExpectProp(right, 'Left', 'Top')
errors += ExpectProp(right, 'Right', 'Right')
- if not errors: InfoOut.Log('Passed PropertyTest')
- return errors
-
-
-def ExpectText(node, text, val):
- found = node.Replace(text)
- if found != val:
- ErrOut.Log('Got replacement %s expecting %s' % (found, val))
- return 1
- return 0
-
-#
-# Verify text replacement
-#
-def ReplaceTest():
- errors = 0
- left = BuildNode('Left', ['Left=Left'])
- right = BuildNode('Right', ['Right=Right'])
- top = BuildNode('Top', ['Left=Top', 'Right=Top'], [left, right])
-
- errors += ExpectText(top, '$Left$', 'Top')
- errors += ExpectText(top, '$Right$', 'Top')
-
- errors += ExpectText(left, '$Left$', 'Left')
- errors += ExpectText(left, '$Right$', 'Top')
-
- errors += ExpectText(right, '$Left$', 'Top')
- errors += ExpectText(right, '$Right$', 'Right')
-
- if not errors: InfoOut.Log('Passed ReplaceTest')
- return errors
-
-
-def MultiParentTest():
- errors = 0
-
- parent1 = BuildNode('parent1', ['PARENT1=parent1', 'TOPMOST=$TOP$'])
- parent2 = BuildNode('parent2', ['PARENT1=parent2', 'PARENT2=parent2'])
- child = BuildNode('child', ['CHILD=child'], parents=[parent1, parent2])
- BuildNode('top', ['TOP=top'], children=[parent1])
-
- errors += ExpectText(child, '$CHILD$', 'child')
- errors += ExpectText(child, '$PARENT1$', 'parent1')
- errors += ExpectText(child, '$PARENT2$', 'parent2')
-
- # Verify recursive resolution
- errors += ExpectText(child, '$TOPMOST$', 'top')
-
- if not errors: InfoOut.Log('Passed MultiParentTest')
+ if not errors:
+ InfoOut.Log('Passed PropertyTest')
return errors
def Main():
errors = 0
errors += PropertyTest()
- errors += ReplaceTest()
- errors += MultiParentTest()
if errors:
ErrOut.Log('IDLNode failed with %d errors.' % errors)
« no previous file with comments | « ppapi/generators/idl_node.py ('k') | tools/json_schema_compiler/idl_schema.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698