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

Side by Side Diff: appengine/components/components/config/validation_context.py

Issue 2013943002: Changing license header, again! (Closed) Base URL: git@github.com:luci/luci-py.git@master
Patch Set: Fixed third parties Created 4 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 unified diff | Download patch
OLDNEW
1 # Copyright 2015 The LUCI Authors. All rights reserved. 1 # Copyright 2015 The LUCI Authors. All rights reserved.
2 # Use of this source code is governed by the Apache v2.0 license that can be 2 # Use of this source code is governed under the Apache License, Version 2.0
3 # found in the LICENSE file. 3 # that can be found in the LICENSE file.
4 4
5 """Defines `Context` class, convenient for customizable validation. 5 """Defines `Context` class, convenient for customizable validation.
6 6
7 Usage: 7 Usage:
8 8
9 def validate(value, ctx=None): 9 def validate(value, ctx=None):
10 ctx = ctx or Context.raise_on_error() 10 ctx = ctx or Context.raise_on_error()
11 if value['foo'] < 0: 11 if value['foo'] < 0:
12 ctx.error('foo is too low: %d', value['foo']) 12 ctx.error('foo is too low: %d', value['foo'])
13 if len(value['bar']) == 0: 13 if len(value['bar']) == 0:
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 text = '%s%s' % (prefix, text) 145 text = '%s%s' % (prefix, text)
146 raise exc_type(text) 146 raise exc_type(text)
147 return cls(on_message=on_message) 147 return cls(on_message=on_message)
148 148
149 @classmethod 149 @classmethod
150 def logging(cls, logger=None): 150 def logging(cls, logger=None):
151 """Returns a context that logs all messages.""" 151 """Returns a context that logs all messages."""
152 logger = logger or logging.getLogger() 152 logger = logger or logging.getLogger()
153 on_message = lambda msg: logger.log(msg.severity, msg.text) 153 on_message = lambda msg: logger.log(msg.severity, msg.text)
154 return cls(on_message=on_message) 154 return cls(on_message=on_message)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698