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

Side by Side Diff: build/android/pylib/utils/decorators.py

Issue 2664873002: Add logdog_helper script. (Closed)
Patch Set: Update one use of AddLink to SetLink I missed Created 3 years, 10 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 unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright 2017 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
5 import functools
6 import logging
7
8
9 def Memoize(f):
10 """Decorator to cache return values of function."""
11 memoize_dict = {}
12 @functools.wraps(f)
13 def wrapper(*args, **kwargs):
14 key = repr((args, kwargs))
15 if key not in memoize_dict:
16 memoize_dict[key] = f(*args, **kwargs)
17 return memoize_dict[key]
18 return wrapper
19
20
21 def NoRaiseException(default_return_value=None, exception_message=''):
22 """Returns decorator that catches and logs uncaught Exceptions.
23
24 Args:
25 default_return_value: Value to return in the case of uncaught Exception.
26 exception_message: Message for uncaught exceptions.
27 """
28 def decorator(f):
29 @functools.wraps(f)
30 def wrapper(*args, **kwargs):
31 try:
32 return f(*args, **kwargs)
33 except Exception: # pylint: disable=broad-except
34 logging.exception(exception_message)
35 return default_return_value
36 return wrapper
37 return decorator
OLDNEW
« no previous file with comments | « build/android/pylib/results/json_results.py ('k') | build/android/pylib/utils/decorators_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698