2020-03-12 15:04:31 +00:00
|
|
|
from six.moves.urllib.parse import quote, urlparse, urlunparse
|
2019-06-10 17:00:28 +00:00
|
|
|
import six
|
|
|
|
import fnmatch
|
|
|
|
|
|
|
|
|
|
|
|
def get_config_object_matcher(**patterns):
|
|
|
|
unsupported = {k: v for k, v in patterns.items() if not isinstance(v, six.string_types)}
|
|
|
|
if unsupported:
|
|
|
|
raise ValueError('Unsupported object matcher (expecting string): %s'
|
|
|
|
% ', '.join('%s=%s' % (k, v) for k, v in unsupported.items()))
|
|
|
|
|
|
|
|
def _matcher(**kwargs):
|
|
|
|
for key, value in kwargs.items():
|
|
|
|
if not value:
|
|
|
|
continue
|
|
|
|
pat = patterns.get(key)
|
|
|
|
if pat and fnmatch.fnmatch(value, pat):
|
|
|
|
return True
|
|
|
|
return _matcher
|
2020-03-12 15:04:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
def quote_url(url):
|
|
|
|
parsed = urlparse(url)
|
|
|
|
if parsed.scheme not in ('http', 'https'):
|
|
|
|
return url
|
|
|
|
parsed = parsed._replace(path=quote(parsed.path))
|
|
|
|
return urlunparse(parsed)
|