36 Library for processing XML substitution args. 42 from cStringIO
import StringIO
44 from io
import StringIO
49 Base class for exceptions in substitution_args routines 54 Exception for missing $(arg) values 59 cmd =
'$(%s)' % command_with_args
60 idx1 = resolved.find(cmd)
61 idx2 = idx1 +
len(cmd)
62 return resolved[0:idx1], resolved[idx2:]
68 path, rest = value,
'' 70 path, rest = value[0:idx], value[idx:]
75 path = path.replace(
'/', os.sep)
76 path = path.replace(
'\\', os.sep)
80 def _arg(resolved, a, args, context):
84 :returns: updated resolved argument, ``str`` 85 :raises: :exc:`ArgException` If arg invalidly specified 92 if 'arg' not in context:
94 arg_context = context[
'arg']
97 if arg_name
in arg_context:
98 arg_value = arg_context[arg_name]
99 return resolved.replace(
"$(%s)"%a, arg_value)
106 Resolves substitution args (see wiki spec U{http://ros.org/wiki/roslaunch}). 108 @param arg_str: string to resolve zero or more substitution args 109 in. arg_str may be None, in which case resolve_args will 112 @param context dict: (optional) dictionary for storing results of 113 the 'anon' and 'arg' substitution args. multiple calls to 114 resolve_args should use the same context so that 'anon' 115 substitions resolve consistently. If no context is provided, a 116 new one will be created for each call. Values for the 'arg' 117 context should be stored as a dictionary in the 'arg' key. 119 @param resolve_anon bool: If True (default), will resolve $(anon 120 foo). If false, will leave these args as-is. 121 @type resolve_anon: bool 123 @return str: arg_str with substitution args resolved 125 @raise SubstitutionException: if there is an error resolving substitution args 136 resolved =
_resolve_args(arg_str, context, resolve_anon, commands)
139 resolved =
_resolve_args(resolved, context, resolve_anon, commands)
146 splits = [s
for s
in a.split(
' ')
if s]
147 if not splits[0]
in valid:
151 if command
in commands:
152 resolved = commands[command](resolved, a, args, context)
161 State-machine parser for resolve_args. Substitution args are of the form: 162 $(find package_name)/scripts/foo.py $(export some/attribute blar) non-relevant stuff 164 @param arg_str: argument string to parse args from 166 @raise SubstitutionException: if args are invalidly specified 167 @return: list of arguments 178 elif state == _DOLLAR:
190 args.append(buff.getvalue())
196 elif state == _DOLLAR:
def _separate_first_path(value)
def _resolve_args(arg_str, context, resolve_anon, commands)
def _split_command(resolved, command_with_args)
def _collect_args(arg_str)
def resolve_args(arg_str, context=None, resolve_anon=True)
def _arg(resolved, a, args, context)