diff --git a/ipalib/base.py b/ipalib/base.py index 38b1e8f32..bc2c6b45a 100644 --- a/ipalib/base.py +++ b/ipalib/base.py @@ -216,7 +216,7 @@ def check_name(name): >>> check_name('MyName') Traceback (most recent call last): ... - ValueError: name must match '^[a-z][_a-z0-9]*[a-z0-9]$'; got 'MyName' + ValueError: name must match '^[a-z][_a-z0-9]*[a-z0-9]$|^[a-z]$'; got 'MyName' Also, this function will raise a ``TypeError`` if ``name`` is not an ``str`` instance. For example: diff --git a/ipalib/config.py b/ipalib/config.py index 5eef03b08..5311f9904 100644 --- a/ipalib/config.py +++ b/ipalib/config.py @@ -74,11 +74,11 @@ class Env(object): >>> env.BadName = 'Wont work as an attribute' Traceback (most recent call last): ... - ValueError: name must match '^[a-z][_a-z0-9]*[a-z0-9]$'; got 'BadName' + ValueError: name must match '^[a-z][_a-z0-9]*[a-z0-9]$|^[a-z]$'; got 'BadName' >>> env['BadName'] = 'Also wont work as a dictionary item' Traceback (most recent call last): ... - ValueError: name must match '^[a-z][_a-z0-9]*[a-z0-9]$'; got 'BadName' + ValueError: name must match '^[a-z][_a-z0-9]*[a-z0-9]$|^[a-z]$'; got 'BadName' The variable values can be ``str``, ``int``, or ``float`` instances, or the ``True``, ``False``, or ``None`` constants. When the value provided is an diff --git a/ipalib/constants.py b/ipalib/constants.py index 0ace2a28c..79ddbca8f 100644 --- a/ipalib/constants.py +++ b/ipalib/constants.py @@ -26,7 +26,7 @@ All constants centralised in one file. NULLS = (None, '', u'', tuple(), []) # regular expression NameSpace member names must match: -NAME_REGEX = r'^[a-z][_a-z0-9]*[a-z0-9]$' +NAME_REGEX = r'^[a-z][_a-z0-9]*[a-z0-9]$|^[a-z]$' # Format for ValueError raised when name does not match above regex: NAME_ERROR = 'name must match %r; got %r' diff --git a/ipalib/parameters.py b/ipalib/parameters.py index b6133f1b1..e0b0ed2c5 100644 --- a/ipalib/parameters.py +++ b/ipalib/parameters.py @@ -192,10 +192,6 @@ def parse_param_spec(spec): raise TypeError( TYPE_ERROR % ('spec', str, spec, type(spec)) ) - if len(spec) < 2: - raise ValueError( - 'spec must be at least 2 characters; got %r' % spec - ) _map = { '?': dict(required=False, multivalue=False), '*': dict(required=False, multivalue=True), diff --git a/tests/test_ipalib/test_parameters.py b/tests/test_ipalib/test_parameters.py index 1f0a7aec8..c4b2d7535 100644 --- a/tests/test_ipalib/test_parameters.py +++ b/tests/test_ipalib/test_parameters.py @@ -134,10 +134,6 @@ def test_parse_param_spec(): e = raises(TypeError, f, u'name?') assert str(e) == TYPE_ERROR % ('spec', str, u'name?', unicode) - # Test that ValueError is raised if len(spec) < 2: - e = raises(ValueError, f, 'n') - assert str(e) == "spec must be at least 2 characters; got 'n'" - class DummyRule(object): def __init__(self, error=None):