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

Side by Side Diff: tools/json_schema_compiler/schema_util.py

Issue 23549025: Clean up JSON Schema Compiler. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Removed enum test and added blank lines. Created 7 years, 3 months 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 unified diff | Download patch
« no previous file with comments | « tools/json_schema_compiler/preview.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 """Utilies for the processing of schema python structures. 4 """Utilies for the processing of schema python structures.
5 """ 5 """
6 6
7 import json_parse
8
9 def CapitalizeFirstLetter(value): 7 def CapitalizeFirstLetter(value):
10 return value[0].capitalize() + value[1:] 8 return value[0].capitalize() + value[1:]
11 9
10
12 def GetNamespace(ref): 11 def GetNamespace(ref):
13 return SplitNamespace(ref)[0] 12 return SplitNamespace(ref)[0]
14 13
14
15 def StripNamespace(ref): 15 def StripNamespace(ref):
16 return SplitNamespace(ref)[1] 16 return SplitNamespace(ref)[1]
17 17
18
18 def SplitNamespace(ref): 19 def SplitNamespace(ref):
19 """Returns (namespace, entity) from |ref|, e.g. app.window.AppWindow -> 20 """Returns (namespace, entity) from |ref|, e.g. app.window.AppWindow ->
20 (app.window, AppWindow). If |ref| isn't qualified then returns (None, ref). 21 (app.window, AppWindow). If |ref| isn't qualified then returns (None, ref).
21 """ 22 """
22 if '.' in ref: 23 if '.' in ref:
23 return tuple(ref.rsplit('.', 1)) 24 return tuple(ref.rsplit('.', 1))
24 return (None, ref) 25 return (None, ref)
25 26
27
26 def JsFunctionNameToClassName(namespace_name, function_name): 28 def JsFunctionNameToClassName(namespace_name, function_name):
27 """Transform a fully qualified function name like foo.bar.baz into FooBarBaz 29 """Transform a fully qualified function name like foo.bar.baz into FooBarBaz
28 30
29 Also strips any leading 'Experimental' prefix.""" 31 Also strips any leading 'Experimental' prefix."""
30 parts = [] 32 parts = []
31 full_name = namespace_name + "." + function_name 33 full_name = namespace_name + "." + function_name
32 for part in full_name.split("."): 34 for part in full_name.split("."):
33 parts.append(CapitalizeFirstLetter(part)) 35 parts.append(CapitalizeFirstLetter(part))
34 if parts[0] == "Experimental": 36 if parts[0] == "Experimental":
35 del parts[0] 37 del parts[0]
36 class_name = "".join(parts) 38 class_name = "".join(parts)
37 return class_name 39 return class_name
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/preview.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698