From 56fa454fdd229524999127a5b89cc7c9077b9bd6 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Tue, 5 Aug 2008 06:33:09 +0000 Subject: 47: Added plugable.check_identifier() function; added corresponding unit tests --- ipalib/plugable.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'ipalib/plugable.py') diff --git a/ipalib/plugable.py b/ipalib/plugable.py index 70743f5a..8f2cbc27 100644 --- a/ipalib/plugable.py +++ b/ipalib/plugable.py @@ -21,6 +21,7 @@ Utility classes for registering plugins, base classes for writing plugins. """ +import re import inspect import errors @@ -43,6 +44,16 @@ def from_cli(cli_name): return cli_name.replace('-', '_').replace('.', '__') +def check_identifier(name): + """ + Raises errors.NameSpaceError if `name` is not a valid Python identifier + suitable for use in a NameSpace. + """ + regex = r'^[a-z][_a-z0-9]*[a-z0-9]$' + if re.match(regex, name) is None: + raise errors.NameSpaceError(name, regex) + + class Plugin(object): """ Base class for all plugins. -- cgit