forked from github.com/pypiserver
Merge pull request #196 from mplanchard/125-better-strip
Resolved paste config parsing issue for Python 2
This commit is contained in:
commit
1477158f3a
@ -1,3 +1,4 @@
|
|||||||
|
import os
|
||||||
import re as _re
|
import re as _re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@ -141,10 +142,13 @@ def str2bool(s, default):
|
|||||||
return default
|
return default
|
||||||
|
|
||||||
|
|
||||||
|
def _str_strip(string):
|
||||||
|
"""Provide a generic strip method to pass as a callback."""
|
||||||
|
return string.strip()
|
||||||
|
|
||||||
|
|
||||||
def paste_app_factory(global_config, **local_conf):
|
def paste_app_factory(global_config, **local_conf):
|
||||||
import os
|
"""Parse a paste config and return an app."""
|
||||||
# let's get unicode.strip in Python 2 or str.strip in Python 3:
|
|
||||||
str_strip = type(u"").strip
|
|
||||||
|
|
||||||
def upd_conf_with_bool_item(conf, attr, sdict):
|
def upd_conf_with_bool_item(conf, attr, sdict):
|
||||||
conf[attr] = str2bool(sdict.pop(attr, None), conf[attr])
|
conf[attr] = str2bool(sdict.pop(attr, None), conf[attr])
|
||||||
@ -159,7 +163,7 @@ def paste_app_factory(global_config, **local_conf):
|
|||||||
if value is not None:
|
if value is not None:
|
||||||
conf[attr] = int(value)
|
conf[attr] = int(value)
|
||||||
|
|
||||||
def upd_conf_with_list_item(conf, attr, sdict, sep=' ', parse=str_strip):
|
def upd_conf_with_list_item(conf, attr, sdict, sep=' ', parse=_str_strip):
|
||||||
values = sdict.pop(attr, None)
|
values = sdict.pop(attr, None)
|
||||||
if values:
|
if values:
|
||||||
conf[attr] = list(filter(None, map(parse, values.split(sep))))
|
conf[attr] = list(filter(None, map(parse, values.split(sep))))
|
||||||
|
@ -27,7 +27,9 @@ import pypiserver
|
|||||||
{},
|
{},
|
||||||
{'root': '~/stable_packages'},
|
{'root': '~/stable_packages'},
|
||||||
{'root': '~/unstable_packages', 'authenticated': 'upload',
|
{'root': '~/unstable_packages', 'authenticated': 'upload',
|
||||||
'passwords': '~/htpasswd'}
|
'passwords': '~/htpasswd'},
|
||||||
|
# Verify that the strip parser works properly.
|
||||||
|
{'authenticated': str('upload')},
|
||||||
])
|
])
|
||||||
def test_paste_app_factory(conf_options, monkeypatch):
|
def test_paste_app_factory(conf_options, monkeypatch):
|
||||||
"""Test the paste_app_factory method"""
|
"""Test the paste_app_factory method"""
|
||||||
|
Loading…
Reference in New Issue
Block a user