Use libyaml for faster loading and saving
if installed
This commit is contained in:
parent
439a6ec515
commit
64bf35a7e9
1 changed files with 9 additions and 2 deletions
|
|
@ -25,6 +25,13 @@ import tempfile
|
||||||
import logging
|
import logging
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
try:
|
||||||
|
from yaml import CLoader as Loader
|
||||||
|
from yaml import CDumper as Dumper
|
||||||
|
except ImportError:
|
||||||
|
from yaml import Loader
|
||||||
|
from yaml import Dumper
|
||||||
|
|
||||||
from .iconfig import IConfig, ConfigError
|
from .iconfig import IConfig, ConfigError
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -42,7 +49,7 @@ class YamlConfig(IConfig):
|
||||||
logging.debug(u'Loading application configuration file: %s.' % self.path)
|
logging.debug(u'Loading application configuration file: %s.' % self.path)
|
||||||
try:
|
try:
|
||||||
with open(self.path, 'r') as f:
|
with open(self.path, 'r') as f:
|
||||||
self.values = yaml.load(f)
|
self.values = yaml.load(f, Loader=Loader)
|
||||||
logging.debug(u'Application configuration file loaded: %s.' % self.path)
|
logging.debug(u'Application configuration file loaded: %s.' % self.path)
|
||||||
except IOError:
|
except IOError:
|
||||||
self.save()
|
self.save()
|
||||||
|
|
@ -55,7 +62,7 @@ class YamlConfig(IConfig):
|
||||||
# write in a temporary file to avoid corruption problems
|
# write in a temporary file to avoid corruption problems
|
||||||
fd, path = tempfile.mkstemp(dir=os.path.dirname(self.path))
|
fd, path = tempfile.mkstemp(dir=os.path.dirname(self.path))
|
||||||
with os.fdopen(fd, 'w') as f:
|
with os.fdopen(fd, 'w') as f:
|
||||||
yaml.dump(self.values, f)
|
yaml.dump(self.values, f, Dumper=Dumper)
|
||||||
os.rename(path, self.path)
|
os.rename(path, self.path)
|
||||||
|
|
||||||
def get(self, *args, **kwargs):
|
def get(self, *args, **kwargs):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue