| OLD | NEW |
| 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 |
| 12 def GetNamespace(ref): | 10 def GetNamespace(ref): |
| 13 return SplitNamespace(ref)[0] | 11 return SplitNamespace(ref)[0] |
| 14 | 12 |
| 15 def StripNamespace(ref): | 13 def StripNamespace(ref): |
| 16 return SplitNamespace(ref)[1] | 14 return SplitNamespace(ref)[1] |
| 17 | 15 |
| 18 def SplitNamespace(ref): | 16 def SplitNamespace(ref): |
| 19 """Returns (namespace, entity) from |ref|, e.g. app.window.AppWindow -> | 17 """Returns (namespace, entity) from |ref|, e.g. app.window.AppWindow -> |
| 20 (app.window, AppWindow). If |ref| isn't qualified then returns (None, ref). | 18 (app.window, AppWindow). If |ref| isn't qualified then returns (None, ref). |
| 21 """ | 19 """ |
| 22 if '.' in ref: | 20 if '.' in ref: |
| 23 return tuple(ref.rsplit('.', 1)) | 21 return tuple(ref.rsplit('.', 1)) |
| 24 return (None, ref) | 22 return (None, ref) |
| 25 | 23 |
| 26 def JsFunctionNameToClassName(namespace_name, function_name): | 24 def JsFunctionNameToClassName(namespace_name, function_name): |
| 27 """Transform a fully qualified function name like foo.bar.baz into FooBarBaz | 25 """Transform a fully qualified function name like foo.bar.baz into FooBarBaz |
| 28 | 26 |
| 29 Also strips any leading 'Experimental' prefix.""" | 27 Also strips any leading 'Experimental' prefix.""" |
| 30 parts = [] | 28 parts = [] |
| 31 full_name = namespace_name + "." + function_name | 29 full_name = namespace_name + "." + function_name |
| 32 for part in full_name.split("."): | 30 for part in full_name.split("."): |
| 33 parts.append(CapitalizeFirstLetter(part)) | 31 parts.append(CapitalizeFirstLetter(part)) |
| 34 if parts[0] == "Experimental": | 32 if parts[0] == "Experimental": |
| 35 del parts[0] | 33 del parts[0] |
| 36 class_name = "".join(parts) | 34 class_name = "".join(parts) |
| 37 return class_name | 35 return class_name |
| OLD | NEW |