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

Unified Diff: reviewbot/util.py

Issue 20518002: Implement mail dispatcher app. (Closed) Base URL: https://src.chromium.org/chrome/trunk/tools/
Patch Set: 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
« no previous file with comments | « reviewbot/mail_dispatcher.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: reviewbot/util.py
===================================================================
--- reviewbot/util.py (revision 215841)
+++ reviewbot/util.py (working copy)
@@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import collections
import email.utils
@@ -17,7 +18,7 @@
return property(get_property)
-class LazyDict(object):
+class LazyDict(collections.Mapping):
"""A simple immutable and lazy dictionary.
This looks up the actual key values on first access to the key and caches the
@@ -33,18 +34,25 @@
self.items[name] = self.lookup(name)
return self.items[name]
+ def __iter__(self):
+ return self.items.iterkeys()
-class ObjectDict(object):
+ def __len__(self):
+ return len(self.items)
+
+ def __repr__(self):
+ return repr(self.items)
+
+
+class ObjectDict(collections.Mapping):
"""Wraps a dictionary to allow value retrieval in dot notation."""
def __init__(self, data):
- self.data = data
+ self.__data = data
def __getitem__(self, name):
- val = self.data[name]
- if type(val) == dict:
- return ObjectDict(val)
- return val
+ val = self.__data[name]
+ return ObjectDict.wrap(val)
def __getattr__(self, name):
try:
@@ -53,9 +61,21 @@
raise AttributeError(e)
def __iter__(self):
- return self.data.iterkeys()
+ return self.__data.iterkeys()
+ def __len__(self):
+ return len(self.__data)
+ def __repr__(self):
+ return repr(self.__data)
+
+ @staticmethod
+ def wrap(val):
+ if isinstance(val, dict):
+ return ObjectDict(val)
+ return val
+
+
def get_emails(string):
"""Normalizes a string containing a list of email recepients.
« no previous file with comments | « reviewbot/mail_dispatcher.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698