mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-03-30 09:45:53 +00:00
Even more fixes to config parsing
This commit is contained in:
parent
43ff90da9a
commit
d91512d07e
3 changed files with 29 additions and 10 deletions
|
|
@ -43,8 +43,8 @@ collections = ["default", "work"]
|
|||
type = filesystem
|
||||
path = ~/.contacts/
|
||||
fileext = .vcf
|
||||
# Create the directory if it doesn't exist: `True` or `False`
|
||||
#create = True
|
||||
# Create the directory if it doesn't exist: `true` or `false`
|
||||
#create = true
|
||||
#encoding = utf-8
|
||||
|
||||
[storage bob_contacts_remote]
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
'''
|
||||
|
||||
import click
|
||||
import pytest
|
||||
|
||||
from click.testing import CliRunner
|
||||
import os
|
||||
|
|
@ -69,6 +70,19 @@ def test_parse_options():
|
|||
assert type(a[key]) is type(expected[key]) # flake8: noqa
|
||||
|
||||
|
||||
def test_parse_config_value():
|
||||
with pytest.raises(ValueError):
|
||||
utils.parse_config_value('123 # comment!')
|
||||
|
||||
assert utils.parse_config_value('"123 # comment!"') == '123 # comment!'
|
||||
assert utils.parse_config_value('True') is True
|
||||
assert utils.parse_config_value('False') is False
|
||||
assert utils.parse_config_value('Yes') is True
|
||||
assert utils.parse_config_value('3.14') == 3.14
|
||||
assert utils.parse_config_value('') == ''
|
||||
assert utils.parse_config_velue('""') == ''
|
||||
|
||||
|
||||
def test_get_password_from_netrc(monkeypatch):
|
||||
username = 'foouser'
|
||||
password = 'foopass'
|
||||
|
|
|
|||
|
|
@ -66,27 +66,32 @@ def uniq(s):
|
|||
|
||||
|
||||
def parse_config_value(value):
|
||||
if value in ('on', 'yes'):
|
||||
try:
|
||||
return json.loads(value)
|
||||
except ValueError:
|
||||
rv = value
|
||||
|
||||
if value.lower() in ('on', 'true', 'yes'):
|
||||
logger.warning('{} is deprecated for the config, please use true.\n'
|
||||
'The old form will be removed in 0.4.0.'
|
||||
.format(value))
|
||||
return True
|
||||
if value in ('off', 'no'):
|
||||
if value.lower() in ('off', 'false', 'no'):
|
||||
logger.warning('{} is deprecated for the config, please use false.\n'
|
||||
'The old form will be removed in 0.4.0.'
|
||||
.format(value))
|
||||
return False
|
||||
if value == 'None':
|
||||
if value.lower() == 'none':
|
||||
logger.warning('None is deprecated for the config, please use null.\n'
|
||||
'The old form will be removed in 0.4.0.')
|
||||
return None
|
||||
|
||||
try:
|
||||
rv = json.loads(value)
|
||||
except ValueError:
|
||||
rv = value
|
||||
if '#' in value:
|
||||
raise ValueError('Invalid value:{}\n'
|
||||
'Use double quotes (") if you want to use hashes in '
|
||||
'your value.')
|
||||
|
||||
if isinstance(rv, (bytes, text_type)) and len(value.splitlines()) > 1:
|
||||
if len(value.splitlines()) > 1:
|
||||
# ConfigParser's barrier for mistaking an arbitrary line for the
|
||||
# continuation of a value is awfully low. The following example will
|
||||
# also contain the second line in the value:
|
||||
|
|
|
|||
Loading…
Reference in a new issue