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

Unified Diff: tools/telemetry/telemetry/core/chrome/camel_case_converter.py

Issue 21682002: Expose GPU information to Telemetry. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Refactored more code into WebSocketBrowserConnection on nduca's request. Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: tools/telemetry/telemetry/core/chrome/camel_case_converter.py
diff --git a/tools/telemetry/telemetry/core/chrome/camel_case_converter.py b/tools/telemetry/telemetry/core/chrome/camel_case_converter.py
new file mode 100644
index 0000000000000000000000000000000000000000..1da6fa01a3cef0734e86fbc55774f7b9095a5922
--- /dev/null
+++ b/tools/telemetry/telemetry/core/chrome/camel_case_converter.py
@@ -0,0 +1,40 @@
+# Copyright (c) 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.
+
+class CamelCaseConverter(object):
+ """Helper class which helps convert between the camel case and
+ underscore naming conventions.
+ """
+
+ @classmethod
+ def FromCamelCase(cls, obj):
+ """Descends recursively into the object obj, converting all
+ attributes' names from camelCase to underscore naming
+ convention. Returns a newly allocated object of the same
+ structure as the input. Handles nested structures of
+ dictionaries and lists.
+ """
+
+ output = None
+ if isinstance(obj, dict):
+ output = dict()
+ for k, v in obj.iteritems():
+ output[cls.__CamelCaseToUnderscore(k)] = cls.FromCamelCase(v)
+ elif isinstance(obj, list):
+ output = []
+ for item in obj:
+ output.append(cls.FromCamelCase(item))
+ else:
+ output = obj
+ return output
+
+ @classmethod
+ def __CamelCaseToUnderscore(cls, input_string):
+ result = ""
+ for c in input_string:
+ if c.isupper():
+ result += "_" + c.lower()
+ else:
+ result += c
+ return result

Powered by Google App Engine
This is Rietveld 408576698