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