Allow one-character Param names

This is done explicitly to support the l/localityname attribute.
This commit is contained in:
Rob Crittenden 2010-02-12 11:01:23 -05:00 committed by Jason Gerard DeRose
parent b31f259b1a
commit 338578d10a
5 changed files with 4 additions and 12 deletions

View File

@ -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:

View File

@ -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

View File

@ -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'

View File

@ -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),

View File

@ -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):