Commits

Antoine Millet committed 92ac960

Added encoding management on the parser

Comments (0)

Files changed (2)

dotconf/parser.py

     >>> print lexer.next()
     """
 
-    def __init__(self, **kwargs):
+    def __init__(self, encoding='utf-8', **kwargs):
         self._lexer = lex.lex(module=self, **kwargs)
+        self._encoding = encoding
 
     #
     # Tokens definition
     def t_TEXT(self, token):
         r'(["]([\\]["]|[^"]|)*["]|[\']([\\][\']|[^\'])*[\'])'
         value = token.value[1:-1].replace('\\' + token.value[0], token.value[0])
-        token.value = value
+        token.value = value.decode(self._encoding)
         # Count the lines in the string:
         token.lexer.lineno += value.count('\n')
         return token

dotconf/schema/types.py

 
     """
 
-    def __init__(self):
+    def __init__(self, encoding=None):
         super(String, self).__init__()
+        self._encoding = encoding
 
     def validate(self, value):
-        return str(value)
+        if self._encoding is not None:
+            value = value.encode(self._encoding)
+        return value
+
 
     def cast(self, value):
         return value