Skip to content

Commit

Permalink
Merge branch 'master' into 4914-urllib-python3
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Sep 6, 2019
2 parents 82f5ab1 + e63a4ef commit 33cf3cf
Show file tree
Hide file tree
Showing 61 changed files with 4,354 additions and 1,060 deletions.
2 changes: 1 addition & 1 deletion ckan/authz.py
Expand Up @@ -8,7 +8,7 @@
from logging import getLogger

from ckan.common import config
from paste.deploy.converters import asbool
from ckan.common import asbool

import ckan.plugins as p
import ckan.model as model
Expand Down
37 changes: 37 additions & 0 deletions ckan/common.py
Expand Up @@ -12,6 +12,7 @@

import flask
import pylons
import six

from werkzeug.local import Local, LocalProxy

Expand Down Expand Up @@ -208,3 +209,39 @@ def _get_session():
# Provide a `c` alias for `g` for backwards compatibility
g = c = LocalProxy(_get_c)
session = LocalProxy(_get_session)

truthy = frozenset([u'true', u'yes', u'on', u'y', u't', u'1'])
falsy = frozenset([u'false', u'no', u'off', u'n', u'f', u'0'])


def asbool(obj):
if isinstance(obj, six.string_types):
obj = obj.strip().lower()
if obj in truthy:
return True
elif obj in falsy:
return False
else:
raise ValueError(u"String is not true/false: {}".format(obj))
return bool(obj)


def asint(obj):
try:
return int(obj)
except (TypeError, ValueError):
raise ValueError(u"Bad integer value: {}".format(obj))


def aslist(obj, sep=None, strip=True):
if isinstance(obj, six.string_types):
lst = obj.split(sep)
if strip:
lst = [v.strip() for v in lst]
return lst
elif isinstance(obj, (list, tuple)):
return obj
elif obj is None:
return []
else:
return [obj]
2 changes: 1 addition & 1 deletion ckan/config/middleware/flask_app.py
Expand Up @@ -18,7 +18,7 @@
from flask_babel import Babel

from beaker.middleware import SessionMiddleware
from paste.deploy.converters import asbool
from ckan.common import asbool
from fanstatic import Fanstatic
from repoze.who.config import WhoConfig
from repoze.who.middleware import PluggableAuthenticationMiddleware
Expand Down
2 changes: 1 addition & 1 deletion ckan/config/middleware/pylons_app.py
Expand Up @@ -9,7 +9,7 @@
from paste.cascade import Cascade
from paste.registry import RegistryManager
from paste.urlparser import StaticURLParser
from paste.deploy.converters import asbool
from ckan.common import asbool
from paste.fileapp import _FileIter
from pylons.middleware import ErrorHandler, StatusCodeRedirect
from routes.middleware import RoutesMiddleware
Expand Down
2 changes: 1 addition & 1 deletion ckan/controllers/package.py
Expand Up @@ -7,7 +7,7 @@
import cgi

from ckan.common import config
from paste.deploy.converters import asbool
from ckan.common import asbool
import paste.fileapp
from six import string_types, text_type

Expand Down
2 changes: 1 addition & 1 deletion ckan/controllers/user.py
Expand Up @@ -3,7 +3,7 @@
import logging

from ckan.common import config
from paste.deploy.converters import asbool
from ckan.common import asbool
from six import text_type

import ckan.lib.base as base
Expand Down

0 comments on commit 33cf3cf

Please sign in to comment.