Commit 2cefa851 authored by Greg Ward's avatar Greg Ward

Various docstring tweaks.

Fixed 'subst_vars()' so it actually blows up like the docstring claims
  (and fixed the docstring not to claim it handles ${var}, which it
  doesn't).
parent e125b16f
"""distutils.util """distutils.util
Miscellaneous utility functions -- anything that doesn't fit into Miscellaneous utility functions -- anything that doesn't fit into
one of the other *util.py modules.""" one of the other *util.py modules.
"""
# created 1999/03/08, Greg Ward # created 1999/03/08, Greg Ward
...@@ -64,9 +65,8 @@ def convert_path (pathname): ...@@ -64,9 +65,8 @@ def convert_path (pathname):
directory separator. Needed because filenames in the setup script are directory separator. Needed because filenames in the setup script are
always supplied in Unix style, and have to be converted to the local always supplied in Unix style, and have to be converted to the local
convention before we can actually use them in the filesystem. Raises convention before we can actually use them in the filesystem. Raises
ValueError if 'pathname' is absolute (starts with '/') or contains ValueError on non-Unix-ish systems if 'pathname' either starts or
local directory separators (unless the local separator is '/', of ends with a slash.
course).
""" """
if os.sep == '/': if os.sep == '/':
return pathname return pathname
...@@ -138,13 +138,12 @@ def check_environ (): ...@@ -138,13 +138,12 @@ def check_environ ():
def subst_vars (str, local_vars): def subst_vars (str, local_vars):
"""Perform shell/Perl-style variable substitution on 'string'. Every """Perform shell/Perl-style variable substitution on 'string'. Every
occurrence of '$' followed by a name, or a name enclosed in braces, is occurrence of '$' followed by a name is considered a variable, and
considered a variable. Every variable is substituted by the value variable is substituted by the value found in the 'local_vars'
found in the 'local_vars' dictionary, or in 'os.environ' if it's not in dictionary, or in 'os.environ' if it's not in 'local_vars'.
'local_vars'. 'os.environ' is first checked/ augmented to guarantee 'os.environ' is first checked/augmented to guarantee that it contains
that it contains certain values: see '_check_environ()'. Raise certain values: see 'check_environ()'. Raise ValueError for any
ValueError for any variables not found in either 'local_vars' or variables not found in either 'local_vars' or 'os.environ'.
'os.environ'.
""" """
check_environ() check_environ()
def _subst (match, local_vars=local_vars): def _subst (match, local_vars=local_vars):
...@@ -154,7 +153,10 @@ def subst_vars (str, local_vars): ...@@ -154,7 +153,10 @@ def subst_vars (str, local_vars):
else: else:
return os.environ[var_name] return os.environ[var_name]
return re.sub(r'\$([a-zA-Z_][a-zA-Z_0-9]*)', _subst, str) try:
return re.sub(r'\$([a-zA-Z_][a-zA-Z_0-9]*)', _subst, str)
except KeyError, var:
raise ValueError, "invalid variable '$%s'" % var
# subst_vars () # subst_vars ()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment