diff options
author | DHNishi@gmail.com <DHNishi@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-10 23:14:04 +0000 |
---|---|---|
committer | DHNishi@gmail.com <DHNishi@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-10 23:14:04 +0000 |
commit | baed4d3ddf78ceb4661ed9414248dfd8baf1b8ab (patch) | |
tree | 920214c422efc03a58fc9b5c7d5c08e92260dc06 | |
parent | 9879b5d724763606e4d69da859e690dc5d06b0ef (diff) | |
download | chromium_src-baed4d3ddf78ceb4661ed9414248dfd8baf1b8ab.zip chromium_src-baed4d3ddf78ceb4661ed9414248dfd8baf1b8ab.tar.gz chromium_src-baed4d3ddf78ceb4661ed9414248dfd8baf1b8ab.tar.bz2 |
Clean up JSON Schema Compiler's pylint errors.
Review URL: https://chromiumcodereview.appspot.com/23549025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@222389 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | tools/json_schema_compiler/cc_generator.py | 58 | ||||
-rwxr-xr-x | tools/json_schema_compiler/compiler.py | 7 | ||||
-rw-r--r-- | tools/json_schema_compiler/cpp_bundle_generator.py | 18 | ||||
-rw-r--r-- | tools/json_schema_compiler/cpp_generator.py | 4 | ||||
-rw-r--r-- | tools/json_schema_compiler/cpp_type_generator.py | 4 | ||||
-rw-r--r-- | tools/json_schema_compiler/cpp_util.py | 9 | ||||
-rw-r--r-- | tools/json_schema_compiler/dart_generator.py | 11 | ||||
-rwxr-xr-x | tools/json_schema_compiler/dart_generator_test.py | 6 | ||||
-rw-r--r-- | tools/json_schema_compiler/dart_test/enums.idl | 12 | ||||
-rw-r--r-- | tools/json_schema_compiler/h_generator.py | 8 | ||||
-rw-r--r-- | tools/json_schema_compiler/idl_schema.py | 12 | ||||
-rwxr-xr-x | tools/json_schema_compiler/idl_schema_test.py | 6 | ||||
-rw-r--r-- | tools/json_schema_compiler/json_parse.py | 2 | ||||
-rw-r--r-- | tools/json_schema_compiler/json_schema.py | 6 | ||||
-rwxr-xr-x | tools/json_schema_compiler/json_schema_test.py | 2 | ||||
-rwxr-xr-x | tools/json_schema_compiler/model_test.py | 3 | ||||
-rwxr-xr-x | tools/json_schema_compiler/preview.py | 4 | ||||
-rw-r--r-- | tools/json_schema_compiler/schema_util.py | 6 |
18 files changed, 93 insertions, 85 deletions
diff --git a/tools/json_schema_compiler/cc_generator.py b/tools/json_schema_compiler/cc_generator.py index 45f4d9d..9935e1c 100644 --- a/tools/json_schema_compiler/cc_generator.py +++ b/tools/json_schema_compiler/cc_generator.py @@ -3,11 +3,9 @@ # found in the LICENSE file. from code import Code -from model import PropertyType, Type +from model import PropertyType import cpp_util -import model import schema_util -import sys import util_cc_helper class CCGenerator(object): @@ -20,6 +18,7 @@ class CCGenerator(object): self._type_generator, self._cpp_namespace).Generate() + class _Generator(object): """A .cc generator for a namespace. """ @@ -349,7 +348,7 @@ class _Generator(object): is_ptr=is_ptr))) if prop.optional: - c.Eblock('}'); + c.Eblock('}') if type_.additional_properties is not None: if type_.additional_properties.property_type == PropertyType.ANY: @@ -382,7 +381,7 @@ class _Generator(object): """ c = Code() c.Sblock('scoped_ptr<base::Value> %s::ToValue() const {' % cpp_namespace) - c.Append('scoped_ptr<base::Value> result;'); + c.Append('scoped_ptr<base::Value> result;') for choice in type_.choices: choice_var = 'as_%s' % choice.unix_name (c.Sblock('if (%s) {' % choice_var) @@ -406,9 +405,8 @@ class _Generator(object): # TODO(kalman): use function.unix_name not Classname. function_namespace = cpp_util.Classname(function.name) - """Windows has a #define for SendMessage, so to avoid any issues, we need - to not use the name. - """ + # Windows has a #define for SendMessage, so to avoid any issues, we need + # to not use the name. if function_namespace == 'SendMessage': function_namespace = 'PassMessage' (c.Append('namespace %s {' % function_namespace) @@ -738,28 +736,28 @@ class _Generator(object): dst_var, failure_value, is_ptr=False): - """Returns Code that converts a ListValue of string constants from - |src_var| into an array of enums of |type_| in |dst_var|. On failure, - returns |failure_value|. - """ - c = Code() - accessor = '.' - if is_ptr: - accessor = '->' - cpp_type = self._type_helper.GetCppType(item_type, is_in_container=True) - c.Append('%s.reset(new std::vector<%s>);' % - (dst_var, cpp_util.PadForGenerics(cpp_type))) - (c.Sblock('for (base::ListValue::const_iterator it = %s->begin(); ' - 'it != %s->end(); ++it) {' % (src_var, src_var)) - .Append('%s tmp;' % self._type_helper.GetCppType(item_type)) - .Concat(self._GenerateStringToEnumConversion(item_type, - '(*it)', - 'tmp', - failure_value)) - .Append('%s%spush_back(tmp);' % (dst_var, accessor)) - .Eblock('}') - ) - return c + """Returns Code that converts a ListValue of string constants from + |src_var| into an array of enums of |type_| in |dst_var|. On failure, + returns |failure_value|. + """ + c = Code() + accessor = '.' + if is_ptr: + accessor = '->' + cpp_type = self._type_helper.GetCppType(item_type, is_in_container=True) + c.Append('%s.reset(new std::vector<%s>);' % + (dst_var, cpp_util.PadForGenerics(cpp_type))) + (c.Sblock('for (base::ListValue::const_iterator it = %s->begin(); ' + 'it != %s->end(); ++it) {' % (src_var, src_var)) + .Append('%s tmp;' % self._type_helper.GetCppType(item_type)) + .Concat(self._GenerateStringToEnumConversion(item_type, + '(*it)', + 'tmp', + failure_value)) + .Append('%s%spush_back(tmp);' % (dst_var, accessor)) + .Eblock('}') + ) + return c def _GenerateStringToEnumConversion(self, type_, diff --git a/tools/json_schema_compiler/compiler.py b/tools/json_schema_compiler/compiler.py index 4ecb699..ddab77e 100755 --- a/tools/json_schema_compiler/compiler.py +++ b/tools/json_schema_compiler/compiler.py @@ -25,7 +25,7 @@ from cpp_generator import CppGenerator from cpp_type_generator import CppTypeGenerator from dart_generator import DartGenerator import json_schema -from model import Model, UnixName +from model import Model from schema_loader import SchemaLoader # Names of supported code generators, as specified on the command-line. @@ -78,10 +78,6 @@ def GenerateSchema(generator, sys.exit("Filename %s is illegal. Name files using unix_hacker style." % schema_filename) - # The output filename must match the input filename for gyp to deal with it - # properly. - out_file = namespace.unix_name - # Construct the type generator with all the namespaces in this model. type_generator = CppTypeGenerator(api_model, schema_loader, @@ -124,6 +120,7 @@ def GenerateSchema(generator, return '\n'.join(output_code) + if __name__ == '__main__': parser = optparse.OptionParser( description='Generates a C++ model of an API from JSON schema', diff --git a/tools/json_schema_compiler/cpp_bundle_generator.py b/tools/json_schema_compiler/cpp_bundle_generator.py index 580bca8..c713d55 100644 --- a/tools/json_schema_compiler/cpp_bundle_generator.py +++ b/tools/json_schema_compiler/cpp_bundle_generator.py @@ -31,12 +31,13 @@ def _RemoveDescriptions(node): return [_RemoveDescriptions(v) for v in node] return node + class CppBundleGenerator(object): """This class contains methods to generate code based on multiple schemas. """ def __init__(self, root, model, api_defs, cpp_type_generator, cpp_namespace): - self._root = root; + self._root = root self._model = model self._api_defs = api_defs self._cpp_type_generator = cpp_type_generator @@ -127,6 +128,7 @@ class CppBundleGenerator(object): c.Eblock("}") return c + class _APIHGenerator(object): """Generates the header for API registration / declaration""" def __init__(self, cpp_bundle): @@ -147,11 +149,12 @@ class _APIHGenerator(object): c.Sblock(' public:') c.Append('static void RegisterAll(' 'ExtensionFunctionRegistry* registry);') - c.Eblock('};'); + c.Eblock('};') c.Append() c.Concat(cpp_util.CloseNamespace(self._bundle._cpp_namespace)) return self._bundle._GenerateHeader('generated_api', c) + class _APICCGenerator(object): """Generates a code.Code object for the generated API .cc file""" @@ -199,6 +202,7 @@ class _APICCGenerator(object): c.Append() return c + class _SchemasHGenerator(object): """Generates a code.Code object for the generated schemas .h file""" def __init__(self, cpp_bundle): @@ -208,7 +212,7 @@ class _SchemasHGenerator(object): c = code.Code() c.Append('#include <map>') c.Append('#include <string>') - c.Append(); + c.Append() c.Append('#include "base/strings/string_piece.h"') c.Append() c.Concat(cpp_util.OpenNamespace(self._bundle._cpp_namespace)) @@ -220,11 +224,12 @@ class _SchemasHGenerator(object): c.Append() c.Append('// Gets the API schema named |name|.') c.Append('static base::StringPiece Get(const std::string& name);') - c.Eblock('};'); + c.Eblock('};') c.Append() c.Concat(cpp_util.CloseNamespace(self._bundle._cpp_namespace)) return self._bundle._GenerateHeader('generated_schemas', c) + def _FormatNameAsConstant(name): """Formats a name to be a C++ constant of the form kConstantName""" name = '%s%s' % (name[0].upper(), name[1:]) @@ -232,6 +237,7 @@ def _FormatNameAsConstant(name): lambda m: m.group(0)[1].upper(), name.replace('.', '_')) + class _SchemasCCGenerator(object): """Generates a code.Code object for the generated schemas .cc file""" @@ -267,10 +273,10 @@ class _SchemasCCGenerator(object): namespace = self._bundle._model.namespaces[api.get('namespace')] c.Append('schemas["%s"] = %s;' % (namespace.name, _FormatNameAsConstant(namespace.name))) - c.Eblock('}'); + c.Eblock('}') c.Append() c.Append('std::map<std::string, const char*> schemas;') - c.Eblock('};'); + c.Eblock('};') c.Append() c.Append('base::LazyInstance<Static> g_lazy_instance;') c.Append() diff --git a/tools/json_schema_compiler/cpp_generator.py b/tools/json_schema_compiler/cpp_generator.py index 6dc0513..b765229 100644 --- a/tools/json_schema_compiler/cpp_generator.py +++ b/tools/json_schema_compiler/cpp_generator.py @@ -7,5 +7,5 @@ from h_generator import HGenerator class CppGenerator(object): def __init__(self, type_generator, cpp_namespace): - self.h_generator = HGenerator(type_generator, cpp_namespace) - self.cc_generator = CCGenerator(type_generator, cpp_namespace) + self.h_generator = HGenerator(type_generator, cpp_namespace) + self.cc_generator = CCGenerator(type_generator, cpp_namespace) diff --git a/tools/json_schema_compiler/cpp_type_generator.py b/tools/json_schema_compiler/cpp_type_generator.py index efb712e..4c0306d 100644 --- a/tools/json_schema_compiler/cpp_type_generator.py +++ b/tools/json_schema_compiler/cpp_type_generator.py @@ -3,10 +3,9 @@ # found in the LICENSE file. from code import Code -from model import Namespace, PropertyType, Type +from model import PropertyType import cpp_util from json_parse import OrderedDict -from operator import attrgetter import schema_util class _TypeDependency(object): @@ -21,6 +20,7 @@ class _TypeDependency(object): def GetSortKey(self): return '%s.%s' % (self.type_.namespace.name, self.type_.name) + class CppTypeGenerator(object): """Manages the types of properties and provides utilities for getting the C++ type out of a model.Property diff --git a/tools/json_schema_compiler/cpp_util.py b/tools/json_schema_compiler/cpp_util.py index 2de4229..2d49343 100644 --- a/tools/json_schema_compiler/cpp_util.py +++ b/tools/json_schema_compiler/cpp_util.py @@ -7,7 +7,7 @@ from code import Code from datetime import datetime -from model import Property, PropertyType, Type +from model import PropertyType import os import re @@ -34,6 +34,7 @@ def Classname(s): """ return '_'.join([x[0].upper() + x[1:] for x in re.split('\W', s)]) + def GetAsFundamentalValue(type_, src, dst): """Returns the C++ code for retrieving a fundamental type from a Value into a variable. @@ -48,6 +49,7 @@ def GetAsFundamentalValue(type_, src, dst): PropertyType.STRING: '%s->GetAsString(%s)', }[type_.property_type] % (src, dst) + def GetValueType(type_): """Returns the Value::Type corresponding to the model.Type. """ @@ -64,6 +66,7 @@ def GetValueType(type_): PropertyType.STRING: 'base::Value::TYPE_STRING', }[type_.property_type] + def GetParameterDeclaration(param, type_): """Gets a parameter declaration of a given model.Property and its C++ type. @@ -82,6 +85,7 @@ def GetParameterDeclaration(param, type_): 'name': param.unix_name, } + def GenerateIfndefName(path, filename): """Formats a path and filename as a #define name. @@ -90,12 +94,14 @@ def GenerateIfndefName(path, filename): return (('%s_%s_H__' % (path, filename)) .upper().replace(os.sep, '_').replace('/', '_')) + def PadForGenerics(var): """Appends a space to |var| if it ends with a >, so that it can be compiled within generic types. """ return ('%s ' % var) if var.endswith('>') else var + def OpenNamespace(namespace): """Get opening root namespace declarations. """ @@ -104,6 +110,7 @@ def OpenNamespace(namespace): c.Append('namespace %s {' % component) return c + def CloseNamespace(namespace): """Get closing root namespace declarations. """ diff --git a/tools/json_schema_compiler/dart_generator.py b/tools/json_schema_compiler/dart_generator.py index 3a4c2e3..a9ba0d6 100644 --- a/tools/json_schema_compiler/dart_generator.py +++ b/tools/json_schema_compiler/dart_generator.py @@ -6,8 +6,8 @@ Generator language component for compiler.py that adds Dart language support. """ from code import Code -from model import * -from schema_util import * +from model import Function, PropertyType +from schema_util import StripNamespace import os from datetime import datetime @@ -25,6 +25,7 @@ class DartGenerator(object): def Generate(self, namespace): return _Generator(namespace, self._dart_overrides_dir).Generate() + class _Generator(object): """A .dart generator for a namespace. """ @@ -278,9 +279,9 @@ class _Generator(object): c.Concat(self._GenerateDocumentation(f)) if not self._NeedsProxiedCallback(f): - c.Append("%s => %s;" % (self._GenerateFunctionSignature(f), - self._GenerateProxyCall(f))) - return c + c.Append("%s => %s;" % (self._GenerateFunctionSignature(f), + self._GenerateProxyCall(f))) + return c (c.Sblock("%s {" % self._GenerateFunctionSignature(f)) .Concat(self._GenerateProxiedFunction(f.callback, f.callback.name)) diff --git a/tools/json_schema_compiler/dart_generator_test.py b/tools/json_schema_compiler/dart_generator_test.py index 65ec7f1..fd88625 100755 --- a/tools/json_schema_compiler/dart_generator_test.py +++ b/tools/json_schema_compiler/dart_generator_test.py @@ -6,9 +6,7 @@ import os import sys import unittest -import glob -from dart_generator import DartGenerator from compiler import GenerateSchema # If --rebase is passed to this test, this is set to True, indicating the test @@ -63,9 +61,6 @@ class DartTest(unittest.TestCase): self._RunTest('empty_type') def testEvents(self): - self._RunTest('enums') - - def testEvents(self): self._RunTest('events') def testBasicFunction(self): @@ -77,6 +72,7 @@ class DartTest(unittest.TestCase): def testTags(self): self._RunTest('tags') + if __name__ == '__main__': if '--rebase' in sys.argv: print "Running in rebase mode." diff --git a/tools/json_schema_compiler/dart_test/enums.idl b/tools/json_schema_compiler/dart_test/enums.idl deleted file mode 100644 index 1c82d00..0000000 --- a/tools/json_schema_compiler/dart_test/enums.idl +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// A comment for the enums namespace. -namespace enums { - // A basic enumeration. - enum Enum1 { a, b }; - - // Another basic enumeration. - enum Enum2 { ab, bc, de, ef, fg, hi }; -}; diff --git a/tools/json_schema_compiler/h_generator.py b/tools/json_schema_compiler/h_generator.py index 77356b2..0a2dc89 100644 --- a/tools/json_schema_compiler/h_generator.py +++ b/tools/json_schema_compiler/h_generator.py @@ -3,7 +3,7 @@ # found in the LICENSE file. from code import Code -from model import PropertyType, Type +from model import PropertyType import cpp_util import schema_util @@ -17,6 +17,7 @@ class HGenerator(object): self._type_generator, self._cpp_namespace).Generate() + class _Generator(object): """A .h generator for a namespace. """ @@ -303,9 +304,8 @@ class _Generator(object): c = Code() # TODO(kalman): Use function.unix_name not Classname here. function_namespace = cpp_util.Classname(function.name) - """Windows has a #define for SendMessage, so to avoid any issues, we need - to not use the name. - """ + # Windows has a #define for SendMessage, so to avoid any issues, we need + # to not use the name. if function_namespace == 'SendMessage': function_namespace = 'PassMessage' (c.Append('namespace %s {' % function_namespace) diff --git a/tools/json_schema_compiler/idl_schema.py b/tools/json_schema_compiler/idl_schema.py index 0556236..44a4a55 100644 --- a/tools/json_schema_compiler/idl_schema.py +++ b/tools/json_schema_compiler/idl_schema.py @@ -10,7 +10,6 @@ import re import sys from json_parse import OrderedDict -import schema_util # This file is a peer to json_schema.py. Each of these files understands a # certain format describing APIs (either JSON or IDL), reads files written @@ -85,6 +84,7 @@ def ProcessComment(comment): .replace('\n', '')) return (parent_comment, params) + class Callspec(object): ''' Given a Callspec node representing an IDL function declaration, converts into @@ -106,7 +106,7 @@ class Callspec(object): # Instead we infer any object return values to be optional. # TODO(asargent): fix the IDL parser to support optional return types. if return_type.get('type') == 'object' or '$ref' in return_type: - return_type['optional'] = True; + return_type['optional'] = True for node in self.node.children: parameter = Param(node).process(callbacks) if parameter['name'] in self.comment: @@ -114,6 +114,7 @@ class Callspec(object): parameters.append(parameter) return (self.node.GetName(), parameters, return_type) + class Param(object): ''' Given a Param node representing a function parameter, converts into a Python @@ -127,6 +128,7 @@ class Param(object): self.node, {'name': self.node.GetName()}).process(callbacks) + class Dictionary(object): ''' Given an IDL Dictionary node, converts into a Python dictionary that the JSON @@ -151,6 +153,7 @@ class Dictionary(object): return result + class Member(object): ''' Given an IDL dictionary or interface member, converts into a name/value pair @@ -204,6 +207,7 @@ class Member(object): properties['enum'] = enum_values return name, properties + class Typeref(object): ''' Given a TYPEREF property representing the type of dictionary member or @@ -350,6 +354,7 @@ class Namespace(object): members.append(properties) return members + class IDLSchema(object): ''' Given a list of IDLNodes and IDLAttributes, converts into a Python list @@ -390,6 +395,7 @@ class IDLSchema(object): sys.exit('Did not process %s %s' % (node.cls, node)) return namespaces + def Load(filename): ''' Given the filename of an IDL file, parses it and returns an equivalent @@ -404,6 +410,7 @@ def Load(filename): idl_schema = IDLSchema(idl) return idl_schema.process() + def Main(): ''' Dump a json serialization of parse result for the IDL files whose names @@ -413,5 +420,6 @@ def Main(): schema = Load(filename) print json.dumps(schema, indent=2) + if __name__ == '__main__': Main() diff --git a/tools/json_schema_compiler/idl_schema_test.py b/tools/json_schema_compiler/idl_schema_test.py index 6adbbd7..1f5d7d67 100755 --- a/tools/json_schema_compiler/idl_schema_test.py +++ b/tools/json_schema_compiler/idl_schema_test.py @@ -12,15 +12,18 @@ def getFunction(schema, name): return item raise KeyError('Missing function %s' % name) + def getParams(schema, name): function = getFunction(schema, name) return function['parameters'] + def getType(schema, id): for item in schema['types']: if item['id'] == id: return item + class IdlSchemaTest(unittest.TestCase): def setUp(self): loaded = idl_schema.Load('test/idl_basics.idl') @@ -145,7 +148,7 @@ class IdlSchemaTest(unittest.TestCase): enum_type = getType(schema, 'enum') self.assertEquals(['callback', 'namespace'], enum_type['enum']) - dictionary = getType(schema, 'dictionary'); + dictionary = getType(schema, 'dictionary') self.assertEquals('integer', dictionary['properties']['long']['type']) mytype = getType(schema, 'MyType') @@ -155,5 +158,6 @@ class IdlSchemaTest(unittest.TestCase): self.assertEquals('Foo', params[0]['$ref']) self.assertEquals('enum', params[1]['$ref']) + if __name__ == '__main__': unittest.main() diff --git a/tools/json_schema_compiler/json_parse.py b/tools/json_schema_compiler/json_parse.py index 9502e91..21a5a8f 100644 --- a/tools/json_schema_compiler/json_parse.py +++ b/tools/json_schema_compiler/json_parse.py @@ -3,7 +3,6 @@ # found in the LICENSE file. import json -import logging import os import sys @@ -57,5 +56,6 @@ except ImportError: return simplejson.loads(json_comment_eater.Nom(json_str), object_pairs_hook=OrderedDict) + def IsDict(item): return isinstance(item, (dict, OrderedDict)) diff --git a/tools/json_schema_compiler/json_schema.py b/tools/json_schema_compiler/json_schema.py index 0fa1ba5..ae126c2 100644 --- a/tools/json_schema_compiler/json_schema.py +++ b/tools/json_schema_compiler/json_schema.py @@ -3,11 +3,8 @@ # found in the LICENSE file. import copy -import os -import sys import json_parse -import schema_util def DeleteNodes(item, delete_key): """Deletes the given nodes in item, recursively, that have |delete_key| as @@ -31,15 +28,18 @@ def DeleteNodes(item, delete_key): return item + def Load(filename): with open(filename, 'r') as handle: schemas = json_parse.Parse(handle.read()) return schemas + # A dictionary mapping |filename| to the object resulting from loading the JSON # at |filename|. _cache = {} + def CachedLoad(filename): """Equivalent to Load(filename), but caches results for subsequent calls""" if filename not in _cache: diff --git a/tools/json_schema_compiler/json_schema_test.py b/tools/json_schema_compiler/json_schema_test.py index 11ba61e..80b3946 100755 --- a/tools/json_schema_compiler/json_schema_test.py +++ b/tools/json_schema_compiler/json_schema_test.py @@ -4,7 +4,6 @@ # found in the LICENSE file. import json_schema -import json_schema_test import unittest class JsonSchemaUnittest(unittest.TestCase): @@ -79,5 +78,6 @@ class JsonSchemaUnittest(unittest.TestCase): schema = json_schema.CachedLoad('test/json_schema_test.json') self.assertEquals(compiled, json_schema.DeleteNodes(schema, 'nocompile')) + if __name__ == '__main__': unittest.main() diff --git a/tools/json_schema_compiler/model_test.py b/tools/json_schema_compiler/model_test.py index 5003af9..bdd2009 100755 --- a/tools/json_schema_compiler/model_test.py +++ b/tools/json_schema_compiler/model_test.py @@ -98,7 +98,8 @@ class ModelTest(unittest.TestCase): 'foo_Bar_Baz_box': 'foo_bar_baz_box', } for name in expectations: - self.assertEquals(expectations[name], model.UnixName(name)); + self.assertEquals(expectations[name], model.UnixName(name)) + if __name__ == '__main__': unittest.main() diff --git a/tools/json_schema_compiler/preview.py b/tools/json_schema_compiler/preview.py index 22ed0f2..5c5fee0 100755 --- a/tools/json_schema_compiler/preview.py +++ b/tools/json_schema_compiler/preview.py @@ -8,7 +8,6 @@ import cc_generator import code -import compiler import cpp_type_generator import cpp_util import h_generator @@ -18,12 +17,12 @@ import model import optparse import os import schema_loader -import sys import urlparse from highlighters import ( pygments_highlighter, none_highlighter, hilite_me_highlighter) from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer + class CompilerHandler(BaseHTTPRequestHandler): """A HTTPRequestHandler that outputs the result of tools/json_schema_compiler. """ @@ -327,6 +326,7 @@ updateEverything(); return html.Render() + class PreviewHTTPServer(HTTPServer, object): def __init__(self, server_address, handler, highlighters): super(PreviewHTTPServer, self).__init__(server_address, handler) diff --git a/tools/json_schema_compiler/schema_util.py b/tools/json_schema_compiler/schema_util.py index 7ce399e..b8fb404 100644 --- a/tools/json_schema_compiler/schema_util.py +++ b/tools/json_schema_compiler/schema_util.py @@ -4,17 +4,18 @@ """Utilies for the processing of schema python structures. """ -import json_parse - def CapitalizeFirstLetter(value): return value[0].capitalize() + value[1:] + def GetNamespace(ref): return SplitNamespace(ref)[0] + def StripNamespace(ref): return SplitNamespace(ref)[1] + def SplitNamespace(ref): """Returns (namespace, entity) from |ref|, e.g. app.window.AppWindow -> (app.window, AppWindow). If |ref| isn't qualified then returns (None, ref). @@ -23,6 +24,7 @@ def SplitNamespace(ref): return tuple(ref.rsplit('.', 1)) return (None, ref) + def JsFunctionNameToClassName(namespace_name, function_name): """Transform a fully qualified function name like foo.bar.baz into FooBarBaz |