def test_str2bool(self):
     self.assertTrue(str2bool("TRUE"))
     self.assertTrue(str2bool("trUe"))
     self.assertTrue(str2bool("on"))
     self.assertTrue(str2bool("yes"))
     self.assertTrue(str2bool("1"))
     self.assertFalse(str2bool("FALSE"))
     self.assertFalse(str2bool("fAlSe"))
     self.assertFalse(str2bool("ofF"))
     self.assertFalse(str2bool("no"))
     self.assertFalse(str2bool("0"))
     self.assertRaises(ValueError, str2bool, "42")
     self.assertRaises(ValueError, str2bool, "kumquat")
 def test_str2bool(self):
     self.assertTrue(str2bool("TRUE"))
     self.assertTrue(str2bool("trUe"))
     self.assertTrue(str2bool("on"))
     self.assertTrue(str2bool("yes"))
     self.assertTrue(str2bool("1"))
     self.assertFalse(str2bool("FALSE"))
     self.assertFalse(str2bool("fAlSe"))
     self.assertFalse(str2bool("ofF"))
     self.assertFalse(str2bool("no"))
     self.assertFalse(str2bool("0"))
     self.assertRaises(ValueError, str2bool, "42")
     self.assertRaises(ValueError, str2bool, "kumquat")
Beispiel #3
0
def make_plugin(audiences,
                rememberer_name=None,
                postback_url=None,
                assertion_field=None,
                came_from_field=None,
                csrf_field=None,
                csrf_cookie_name=None,
                challenge_body=None,
                verifier=None,
                check_https=None,
                check_referer=None,
                **kwds):
    """Make a BrowserIDPlugin using values from a .ini config file.

    This is a helper function for loading a BrowserIDPlugin via the
    repoze.who .ini config file system. It converts its arguments from
    strings to the appropriate type then passes them on to the plugin.
    """
    if not audiences:
        audiences = None
    elif isinstance(audiences, basestring):
        audiences = audiences.split()
    if isinstance(challenge_body, basestring):
        try:
            challenge_body = resolveDotted(challenge_body)
        except (ValueError, ImportError):
            with open(challenge_body, "rb") as f:
                challenge_body = f.read()
    if isinstance(verifier, basestring):
        verifier = resolveDotted(verifier)
        if callable(verifier):
            verifier_kwds = {}
            for key, value in kwds.iteritems():
                if key.startswith("verifier_"):
                    verifier_kwds[key[len("verifier_"):]] = value
            verifier = verifier(**verifier_kwds)
    if isinstance(check_https, basestring):
        check_https = str2bool(check_https)
    if isinstance(check_referer, basestring):
        check_referer = str2bool(check_referer)
    plugin = BrowserIDPlugin(audiences, rememberer_name, postback_url,
                             assertion_field, came_from_field, csrf_field,
                             csrf_cookie_name, challenge_body, verifier,
                             check_https, check_referer)
    return plugin
def make_plugin(audiences, rememberer_name=None, postback_url=None,
                assertion_field=None, came_from_field=None, csrf_field=None,
                csrf_cookie_name=None, challenge_body=None, verifier=None,
                check_https=None, check_referer=None, **kwds):
    """Make a BrowserIDPlugin using values from a .ini config file.

    This is a helper function for loading a BrowserIDPlugin via the
    repoze.who .ini config file system. It converts its arguments from
    strings to the appropriate type then passes them on to the plugin.
    """
    if not audiences:
        audiences = None
    elif isinstance(audiences, basestring):
        audiences = audiences.split()
    if isinstance(challenge_body, basestring):
        try:
            challenge_body = resolveDotted(challenge_body)
        except (ValueError, ImportError):
            with open(challenge_body, "rb") as f:
                challenge_body = f.read()
    if isinstance(verifier, basestring):
        verifier = resolveDotted(verifier)
        if callable(verifier):
            verifier_kwds = {}
            for key, value in kwds.iteritems():
                if key.startswith("verifier_"):
                    verifier_kwds[key[len("verifier_"):]] = value
            verifier = verifier(**verifier_kwds)
    if isinstance(check_https, basestring):
        check_https = str2bool(check_https)
    if isinstance(check_referer, basestring):
        check_referer = str2bool(check_referer)
    plugin = BrowserIDPlugin(audiences, rememberer_name, postback_url,
                             assertion_field, came_from_field, csrf_field,
                             csrf_cookie_name, challenge_body, verifier,
                             check_https, check_referer)
    return plugin