schema_util.py 1.1 KB

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