| OLD | NEW |
| (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 class Visitor(object): |
| 6 """Traverse one property of a state's dict""" |
| 7 CONDITION = 'condition' |
| 8 |
| 9 def __init__(self, variable_expander): |
| 10 self._variable_expander = variable_expander |
| 11 |
| 12 def Traverse(self, property_value): |
| 13 for entry_name, entry_value in property_value.iteritems(): |
| 14 if Visitor.CONDITION in entry_value and not self._EvaluateCondition( |
| 15 self._variable_expander.Expand(entry_value[Visitor.CONDITION])): |
| 16 continue |
| 17 self._VisitEntry(entry_name, entry_value) |
| 18 |
| 19 def _EvaluateCondition(self, condition): |
| 20 """Evaluates |condition| using eval(). |
| 21 |
| 22 Args: |
| 23 condition: A condition string. |
| 24 |
| 25 Returns: |
| 26 The result of the evaluated condition. |
| 27 """ |
| 28 return eval(condition, {'__builtins__': {'False': False, 'True': True}}) |
| 29 |
| 30 def _VisitEntry(self, entry_name, entry_value): |
| 31 raise NotImplementedError() |
| OLD | NEW |