Repository: missionpinball/mpf
Issue: YAML parsers thinks hex colors like 1030e0 are exponents

It works if you add quotes around the value, but we should probably hack the yaml processor to ignore these like we do with octals


Changed files:
mpf/file_interfaces/yaml_interface.py, mpf/tests/test_YamlInterface.py

diff --git a/mpf/file_interfaces/yaml_interface.py b/mpf/file_interfaces/yaml_interface.py
index b7dcc57c3..e8d971b23 100644
--- a/mpf/file_interfaces/yaml_interface.py
+++ b/mpf/file_interfaces/yaml_interface.py
@@ -58,12 +58,9 @@ MpfResolver.add_implicit_resolver(
 MpfResolver.add_implicit_resolver(
     u'tag:yaml.org,2002:float',
     re.compile(u'''^(?:
-     [-+]?(?:[0-9][0-9_]*)\\\\.[0-9_]*(?:[eE][-+]?[0-9]+)?
-    |[-+]?(?:[0-9][0-9_]*)(?:[eE][-+]?[0-9]+)
-    |\\\\.[0-9_]+(?:[eE][-+][0-9]+)?
-    |[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\\\.[0-9_]*
-    |[-+]?\\\\.(?:inf|Inf|INF)
-    |\\\\.(?:nan|NaN|NAN))$''', re.X),
+     [-+]?(?:[0-9][0-9_]*)\\\\.[0-9_]*
+    |\\\\.[0-9_]+
+    |[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\\\.[0-9_]*)$''', re.X),
     list(u'-+0123456789.'))
 
 MpfResolver.add_implicit_resolver(
@@ -71,7 +68,6 @@ MpfResolver.add_implicit_resolver(
     re.compile(u'''^(?:[-+]?0b[0-1_]+
     |[-+]?[0-9]+
     |[-+]?0o?[0-7_]+
-    |[-+]?(?:0|[1-9][0-9_]*)
     |[-+]?0x[0-9a-fA-F_]+
     |[-+]?[1-9][0-9_]*(?::[0-5]?[0-9])+)$''', re.X),
     list(u'-+0123456789'))
@@ -110,46 +106,6 @@ MpfResolver.add_implicit_resolver(
     list(u'!&*'))
 
 
-class MpfRoundTripConstructor(RoundTripConstructor):
-
-    """Resolver with fix."""
-
-    def __init__(self):
-        """Initialise."""
-        super().__init__()
-
-    def construct_yaml_int(self, node):
-        """Add int fix."""
-        value = to_str(self.construct_scalar(node))
-        value = value.replace('_', '')
-        sign = +1
-        if value[0] == '-':
-            sign = -1
-        if value[0] in '+-':
-            value = value[1:]
-        if value == '0':
-            return 0
-        elif value.startswith('0b'):
-            return sign * int(value[2:], 2)
-        elif value.startswith('0x'):
-            return sign * int(value[2:], 16)
-        elif value.startswith('0o'):
-            return sign * int(value[2:], 8)
-        # elif value[0] == '0':
-        #    return sign*int(value, 8)
-        elif ':' in value:
-            digits = [int(part) for part in value.split(':')]
-            digits.reverse()
-            base = 1
-            int_value = 0
-            for digit in digits:
-                int_value += digit * base
-                base *= 60
-            return sign * int_value
-        else:
-            return sign * int(value)
-
-
 class MpfConstructor(Constructor):
 
     """Constructor with fix."""
@@ -188,47 +144,8 @@ class MpfConstructor(Constructor):
             mapping[key] = value
         return mapping
 
-    def construct_yaml_int(self, node):
-        """Add int fix."""
-        value = to_str(self.construct_scalar(node))
-        value = value.replace('_', '')
-        sign = +1
-        if value[0] == '-':
-            sign = -1
-        if value[0] in '+-':
-            value = value[1:]
-        if value == '0':
-            return 0
-        elif value.startswith('0b'):
-            return sign * int(value[2:], 2)
-        elif value.startswith('0x'):
-            return sign * int(value[2:], 16)
-        elif value.startswith('0o'):
-            return sign * int(value[2:], 8)
-        # elif value[0] == '0':
-        #    return sign*int(value, 8)
-        elif ':' in value:
-            digits = [int(part) for part in value.split(':')]
-            digits.reverse()
-            base = 1
-            int_value = 0
-            for digit in digits:
-                int_value += digit * base
-                base *= 60
-            return sign * int_value
-        else:
-            return sign * int(value)
-
-MpfRoundTripConstructor.add_constructor(
-    u'tag:yaml.org,2002:int',
-    MpfRoundTripConstructor.construct_yaml_int)
-
-MpfConstructor.add_constructor(
-    u'tag:yaml.org,2002:int',
-    MpfConstructor.construct_yaml_int)
-
 
-class MpfRoundTripLoader(Reader, RoundTripScanner, Parser, Composer, MpfRoundTripConstructor, MpfResolver):
+class MpfRoundTripLoader(Reader, RoundTripScanner, Parser, Composer, RoundTripConstructor, MpfResolver):
 
     """Config loader which can roundtrip."""
 
@@ -238,7 +155,7 @@ class MpfRoundTripLoader(Reader, RoundTripScanner, Parser, Composer, MpfRoundTri
         RoundTripScanner.__init__(self)
         Parser.__init__(self)
         Composer.__init__(self)
-        MpfRoundTripConstructor.__init__(self)
+        RoundTripConstructor.__init__(self)
         MpfResolver.__init__(self)
 
 
diff --git a/mpf/tests/test_YamlInterface.py b/mpf/tests/test_YamlInterface.py
index 3808b76b3..876bc81f1 100644
--- a/mpf/tests/test_YamlInterface.py
+++ b/mpf/tests/test_YamlInterface.py
@@ -99,7 +99,7 @@ str_1: +1
 str_2: 032
 str_3: on
 str_4: off
-# str_5: 123e45
+str_5: 123e45
 bool_1: yes
 bool_2: no
 bool_3: true