Project

Profile

Help

Revision ebe2010d

IDebe2010d87daa3aa00a5076fe20a2680e9296cf8
Parent 96664dff
Child 12e1b5aa

Added by Vincent Le Goff almost 3 years ago

Add automatic convertion from utf-8 with signature to latin-1 in the configuration if needed

View differences:

src/config.py
34 34
from textwrap import dedent
35 35

  
36 36
from yaml import safe_dump, safe_load
37
from configobj import ConfigObj
37
from configobj import ConfigObj, ParseError
38 38
from validate import Validator
39 39

  
40
from log import main as logger
40 41
from world import World
41 42

  
42 43
class Configuration(object):
......
142 143
                os.mkdir(base)
143 144

  
144 145
        # Create the ConfigObj
145
        config = ConfigObj(fullpath + ".conf", encoding="latin-1",
146
                configspec=spec.split("\n"))
146
        try:
147
            config = ConfigObj(fullpath + ".conf", encoding="latin-1",
148
                    configspec=spec.split("\n"))
149
        except ParseError:
150
            logger.warning("Unable to parse {}, try without encoding".format(
151
                    repr(fullpath)))
152
            config = ConfigObj(fullpath + ".conf", configspec=spec.split("\n"))
153
            config.encoding = "latin-1"
154
            config.write()
147 155

  
148 156
        # Validates the configuration
149 157
        validator = Validator()
src/world.py
36 36
from textwrap import dedent
37 37
from threading import RLock
38 38

  
39
from configobj import ConfigObj
39
from configobj import ConfigObj, ParseError
40 40
from ytranslate import t
41 41

  
42 42
from character import Character
......
152 152
        """).strip("\n")
153 153

  
154 154
        if self.settings is None:
155
            self.settings = ConfigObj(spec.split("\n"), encoding="latin-1")
155
            try:
156
                self.settings = ConfigObj(spec.split("\n"), encoding="latin-1")
157
            except ParseError:
158
                logger.warning("Error while parsing the config file, " \
159
                        "trying without encoding")
160
                self.settings = ConfigObj(spec.split("\n"))
161
                self.settings.encoding = "latin-1"
162
                self.settings.write()
156 163

  
157 164
        connection = self.settings["connection"]
158 165
        connection["name"] = self.name

Also available in: Unified diff