1. Antoine Millet
  2. Dotconf

Commits

Antoine Millet  committed 92ac960

Added encoding management on the parser

  • Participants
  • Parent commits 4efc258
  • Branches master

Comments (0)

Files changed (2)

File dotconf/parser.py

View file
  • Ignore whitespace
     >>> 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

File dotconf/schema/types.py

View file
  • Ignore whitespace
 
     """
 
-    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