1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
#-----------------------------------------------------------------------------
#
# Copyright (c) 2006 by Enthought, Inc.
# All rights reserved.
#
# Author: Dave Peterson <dpeterson@enthought.com>
#
#-----------------------------------------------------------------------------
""" Provides the capability to format a string to a valid python name.
DEPRECATED: Please use the enthought.util.clean_strings module instead.
"""
# Standard library imports.
import keyword
import warnings
def python_name(name):
""" Attempt to make a valid Python identifier out of a name.
DEPRECATED: Please use the enthought.util.clean_strings.python_name
function instead.
"""
warnings.warn('enthought.util.python_name has been ' + \
'deprecated in favor of enthought.util.clean_strings',
DeprecationWarning)
if len(name) > 0:
# Replace spaces with underscores.
name = name.replace(' ', '_').lower()
# If the name is a Python keyword then prefix it with an
# underscore.
if keyword.iskeyword(name):
name = '_' + name
# If the name starts with a digit then prefix it with an
# underscore.
if name[0].isdigit():
name = '_' + name
return name
#### EOF #####################################################################
|