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

Unified Diff: tools/telemetry/third_party/rope/rope/base/prefs.py

Issue 1132103009: Example of refactoring using rope library. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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/third_party/rope/rope/base/prefs.py
diff --git a/tools/telemetry/third_party/rope/rope/base/prefs.py b/tools/telemetry/third_party/rope/rope/base/prefs.py
new file mode 100644
index 0000000000000000000000000000000000000000..2ab45dac541d9ef4150b81dcc65b7af08db770ca
--- /dev/null
+++ b/tools/telemetry/third_party/rope/rope/base/prefs.py
@@ -0,0 +1,41 @@
+class Prefs(object):
+
+ def __init__(self):
+ self.prefs = {}
+ self.callbacks = {}
+
+ def set(self, key, value):
+ """Set the value of `key` preference to `value`."""
+ if key in self.callbacks:
+ self.callbacks[key](value)
+ else:
+ self.prefs[key] = value
+
+ def add(self, key, value):
+ """Add an entry to a list preference
+
+ Add `value` to the list of entries for the `key` preference.
+
+ """
+ if not key in self.prefs:
+ self.prefs[key] = []
+ self.prefs[key].append(value)
+
+ def get(self, key, default=None):
+ """Get the value of the key preference"""
+ return self.prefs.get(key, default)
+
+ def add_callback(self, key, callback):
+ """Add `key` preference with `callback` function
+
+ Whenever `key` is set the callback is called with the
+ given `value` as parameter.
+
+ """
+ self.callbacks[key] = callback
+
+ def __setitem__(self, key, value):
+ self.set(key, value)
+
+ def __getitem__(self, key):
+ return self.get(key)
« no previous file with comments | « tools/telemetry/third_party/rope/rope/base/oi/transform.py ('k') | tools/telemetry/third_party/rope/rope/base/project.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698