Chromium Code Reviews| Index: telemetry/telemetry/value/scalar.py |
| diff --git a/telemetry/telemetry/value/scalar.py b/telemetry/telemetry/value/scalar.py |
| index 2789b81319e9224333c4178683afc3b23dceebec..9b31e719e0c9eb3e384786cfb73fb1498a66151b 100644 |
| --- a/telemetry/telemetry/value/scalar.py |
| +++ b/telemetry/telemetry/value/scalar.py |
| @@ -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 math |
| import numbers |
| from telemetry import value as value_module |
| @@ -68,7 +69,17 @@ class ScalarValue(summarizable.SummarizableValue): |
| def AsDict(self): |
| d = super(ScalarValue, self).AsDict() |
| - d['value'] = self.value |
| + |
| + # Infinity and NaN are left out of JSON for security reasons that do not |
|
eakuefner
2016/05/19 17:30:56
In Telemetry, we don't support string-valued scala
eakuefner
2016/05/19 17:33:04
Sorry, to be even more clear, I mean that you shou
|
| + # apply to our use cases. |
| + if self.value == float('inf'): |
| + d['value'] = 'Infinity' |
| + elif self.value == -float('inf'): |
| + d['value'] = '-Infinity' |
| + elif math.isnan(self.value): |
| + d['value'] = 'NaN' |
| + else: |
| + d['value'] = self.value |
| if self.none_value_reason is not None: |
| d['none_value_reason'] = self.none_value_reason |
| @@ -78,7 +89,17 @@ class ScalarValue(summarizable.SummarizableValue): |
| @staticmethod |
| def FromDict(value_dict, page_dict): |
| kwargs = value_module.Value.GetConstructorKwArgs(value_dict, page_dict) |
| - kwargs['value'] = value_dict['value'] |
| + |
| + # Infinity and NaN are left out of JSON for security reasons that do not |
|
eakuefner
2016/05/19 17:30:56
Here I'd write an additional comment that says 'TB
eakuefner
2016/05/19 17:32:09
And to be clear, I'm not married to the wording; p
|
| + # apply to our use cases. |
| + if value_dict['value'] == 'Infinity': |
|
eakuefner
2016/05/19 17:30:56
And flatten all these cases to this block:
if ...
|
| + kwargs['value'] = float('inf') |
| + elif value_dict['value'] == '-Infinity': |
| + kwargs['value'] = -float('inf') |
| + elif value_dict['value'] == 'NaN': |
| + kwargs['value'] = float('nan') |
| + else: |
| + kwargs['value'] = value_dict['value'] |
| if 'improvement_direction' in value_dict: |
| kwargs['improvement_direction'] = value_dict['improvement_direction'] |