| Index: trunk/src/tools/json_schema_compiler/model.py
|
| ===================================================================
|
| --- trunk/src/tools/json_schema_compiler/model.py (revision 226848)
|
| +++ trunk/src/tools/json_schema_compiler/model.py (working copy)
|
| @@ -7,7 +7,6 @@
|
| from json_parse import OrderedDict
|
| from memoize import memoize
|
|
|
| -
|
| class ParseException(Exception):
|
| """Thrown when data in the model is invalid.
|
| """
|
| @@ -17,7 +16,6 @@
|
| Exception.__init__(
|
| self, 'Model parse exception at:\n' + '\n'.join(hierarchy))
|
|
|
| -
|
| class Model(object):
|
| """Model of all namespaces that comprise an API.
|
|
|
| @@ -36,45 +34,6 @@
|
| self.namespaces[namespace.name] = namespace
|
| return namespace
|
|
|
| -
|
| -def CreateFeature(name, model):
|
| - if isinstance(model, dict):
|
| - return SimpleFeature(name, model)
|
| - return ComplexFeature(name, [SimpleFeature(name, child) for child in model])
|
| -
|
| -
|
| -class ComplexFeature(object):
|
| - """A complex feature which may be made of several simple features.
|
| -
|
| - Properties:
|
| - - |name| the name of the feature
|
| - - |unix_name| the unix_name of the feature
|
| - - |feature_list| a list of simple features which make up the feature
|
| - """
|
| - def __init__(self, feature_name, features):
|
| - self.name = feature_name
|
| - self.unix_name = UnixName(self.name)
|
| - self.feature_list = features
|
| -
|
| -class SimpleFeature(object):
|
| - """A simple feature, which can make up a complex feature, as specified in
|
| - files such as chrome/common/extensions/api/_permission_features.json.
|
| -
|
| - Properties:
|
| - - |name| the name of the feature
|
| - - |unix_name| the unix_name of the feature
|
| - - |channel| the channel where the feature is released
|
| - - |extension_types| the types which can use the feature
|
| - - |whitelist| a list of extensions allowed to use the feature
|
| - """
|
| - def __init__(self, feature_name, feature_def):
|
| - self.name = feature_name
|
| - self.unix_name = UnixName(self.name)
|
| - self.channel = feature_def['channel']
|
| - self.extension_types = feature_def['extension_types']
|
| - self.whitelist = feature_def.get('whitelist')
|
| -
|
| -
|
| class Namespace(object):
|
| """An API namespace.
|
|
|
| @@ -116,7 +75,6 @@
|
| if include_compiler_options else {})
|
| self.documentation_options = json.get('documentation_options', {})
|
|
|
| -
|
| class Origin(object):
|
| """Stores the possible origin of model object as a pair of bools. These are:
|
|
|
| @@ -135,7 +93,6 @@
|
| self.from_client = from_client
|
| self.from_json = from_json
|
|
|
| -
|
| class Type(object):
|
| """A Type defined in the json.
|
|
|
| @@ -242,7 +199,6 @@
|
| else:
|
| raise ParseException(self, 'Unsupported JSON type %s' % json_type)
|
|
|
| -
|
| class Function(object):
|
| """A Function defined in the API.
|
|
|
| @@ -314,7 +270,6 @@
|
| namespace,
|
| origin)
|
|
|
| -
|
| class Property(object):
|
| """A property of a type OR a parameter to a function.
|
| Properties:
|
| @@ -386,7 +341,6 @@
|
|
|
| unix_name = property(GetUnixName, SetUnixName)
|
|
|
| -
|
| class _Enum(object):
|
| """Superclass for enum types with a "name" field, setting up repr/eq/ne.
|
| Enums need to do this so that equality/non-equality work over pickling.
|
| @@ -414,13 +368,11 @@
|
| def __str__(self):
|
| return repr(self)
|
|
|
| -
|
| class _PropertyTypeInfo(_Enum):
|
| def __init__(self, is_fundamental, name):
|
| _Enum.__init__(self, name)
|
| self.is_fundamental = is_fundamental
|
|
|
| -
|
| class PropertyType(object):
|
| """Enum of different types of properties/parameters.
|
| """
|
| @@ -438,7 +390,6 @@
|
| REF = _PropertyTypeInfo(False, "ref")
|
| STRING = _PropertyTypeInfo(True, "string")
|
|
|
| -
|
| @memoize
|
| def UnixName(name):
|
| '''Returns the unix_style name for a given lowerCamelCase string.
|
| @@ -460,13 +411,11 @@
|
| unix_name.append(c.lower())
|
| return ''.join(unix_name)
|
|
|
| -
|
| def _StripNamespace(name, namespace):
|
| if name.startswith(namespace.name + '.'):
|
| return name[len(namespace.name + '.'):]
|
| return name
|
|
|
| -
|
| def _GetModelHierarchy(entity):
|
| """Returns the hierarchy of the given model entity."""
|
| hierarchy = []
|
| @@ -478,7 +427,6 @@
|
| hierarchy.reverse()
|
| return hierarchy
|
|
|
| -
|
| def _GetTypes(parent, json, namespace, origin):
|
| """Creates Type objects extracted from |json|.
|
| """
|
| @@ -488,7 +436,6 @@
|
| types[type_.name] = type_
|
| return types
|
|
|
| -
|
| def _GetFunctions(parent, json, namespace):
|
| """Creates Function objects extracted from |json|.
|
| """
|
| @@ -502,7 +449,6 @@
|
| functions[function.name] = function
|
| return functions
|
|
|
| -
|
| def _GetEvents(parent, json, namespace):
|
| """Creates Function objects generated from the events in |json|.
|
| """
|
| @@ -516,7 +462,6 @@
|
| events[event.name] = event
|
| return events
|
|
|
| -
|
| def _GetProperties(parent, json, namespace, origin):
|
| """Generates Property objects extracted from |json|.
|
| """
|
| @@ -525,12 +470,10 @@
|
| properties[name] = Property(parent, name, property_json, namespace, origin)
|
| return properties
|
|
|
| -
|
| class _PlatformInfo(_Enum):
|
| def __init__(self, name):
|
| _Enum.__init__(self, name)
|
|
|
| -
|
| class Platforms(object):
|
| """Enum of the possible platforms.
|
| """
|
| @@ -540,7 +483,6 @@
|
| MAC = _PlatformInfo("mac")
|
| WIN = _PlatformInfo("win")
|
|
|
| -
|
| def _GetPlatforms(json):
|
| if 'platforms' not in json:
|
| return None
|
|
|