Revision: 557
http://svn.sourceforge.net/pygccxml/?rev=557&view=rev
Author: mbaas
Date: 2006-09-19 00:48:00 -0700 (Tue, 19 Sep 2006)
Log Message:
-----------
Switched to using the string.Template class for doing substitutions. This slightly modified semantics: Undefined variables are no longer treated as being empty but won't get substituted at all.
Modified Paths:
--------------
pyplusplus_dev/pyplusplus/function_transformers/code_manager.py
pyplusplus_dev/pyplusplus/function_transformers/subst.py
Modified: pyplusplus_dev/pyplusplus/function_transformers/code_manager.py
===================================================================
--- pyplusplus_dev/pyplusplus/function_transformers/code_manager.py 2006-09-18 21:45:16 UTC (rev 556)
+++ pyplusplus_dev/pyplusplus/function_transformers/code_manager.py 2006-09-19 07:48:00 UTC (rev 557)
@@ -184,10 +184,14 @@
# RESULT_VAR_ASSIGNMENT
if self.result_var!=None:
self.RESULT_VAR_ASSIGNMENT = "%s = "%self.result_var
+ else:
+ self.RESULT_VAR_ASSIGNMENT = ""
# RESULT_TYPE
if self.result_type!=None:
self.RESULT_TYPE = str(self.result_type)
+ else:
+ self.RESULT_TYPE = ""
# INPUT_PARAMS
self.INPUT_PARAMS = ", ".join(self.input_params)
@@ -195,6 +199,8 @@
# RETURN_STMT
if self.result_expr!=None:
self.RETURN_STMT = "return %s;"%self.result_expr
+ else:
+ self.RETURN_STMT = ""
# _make_name_unique
def _make_name_unique(self, name):
Modified: pyplusplus_dev/pyplusplus/function_transformers/subst.py
===================================================================
--- pyplusplus_dev/pyplusplus/function_transformers/subst.py 2006-09-18 21:45:16 UTC (rev 556)
+++ pyplusplus_dev/pyplusplus/function_transformers/subst.py 2006-09-19 07:48:00 UTC (rev 557)
@@ -9,6 +9,7 @@
"""
import re
+import string
# subst_t
class subst_t:
@@ -16,9 +17,9 @@
This class performs text substitutions on a template string. The
variables are simply stored as attributes inside the class and may
- be of any type that can be converted to a string. An empty string
- is used if a template string references a variable that does not
- exist.
+ be of any type that can be converted to a string.
+ If a template string references a variable that does not exist,
+ the reference is not substituted.
Example::
@@ -76,11 +77,11 @@
def substitute(self, template):
"""Substitute the variables in template and return the result.
- All variables of the form "$<varname>" are replaced with the
- corresponding attribute <varname>. Block variables must appear
- in one single line. The indendation of the variable determines
- the indendation of the entire block.
- Unknown variables will be substituted with an empty string.
+ All variables of the form "$<varname>" or "${varname}" are
+ replaced with the corresponding attribute <varname>. Block
+ variables must appear in one single line. The indendation of
+ the variable determines the indendation of the entire block.
+ References to unknown variables won't get substituted.
@param template: The template string
@type template: str
@@ -108,17 +109,8 @@
code = "\n".join(lines)
# Replace the non-block variables...
- varexpr = re.compile("\$[a-zA-Z_]+|\$\{[a-zA-Z_]+\}")
- while 1:
- m = varexpr.search(code)
- if m==None:
- break
- s = m.start()
- e = m.end()
- key = code[s+1:e]
- if key[0]=="{":
- key = key[1:-1]
- code = "%s%s%s"%(code[:s], getattr(self, key, ""), code[e:])
+ tmpl = string.Template(code)
+ code = tmpl.safe_substitute(self.__dict__)
# Replace trailing blanks on each line...
expr = re.compile("[ ]+$", re.MULTILINE)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|