Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions
string.Template Class Reference
Inheritance diagram for string.Template:
Inheritance graph
[legend]
Collaboration diagram for string.Template:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def substitute
def safe_substitute

Public Attributes

 template

Static Public Attributes

string delimiter = '$'
string idpattern = r'[_a-z][_a-z0-9]*'
 flags = _re.IGNORECASE
string pattern = r""

Private Member Functions

def _invalid

Detailed Description

A string class for supporting $-substitutions.

Definition at line 89 of file string.py.


Constructor & Destructor Documentation

def string.Template.__init__ (   self,
  template 
)

Definition at line 96 of file string.py.

00096 
00097     def __init__(self, template):
00098         self.template = template

Here is the call graph for this function:

Here is the caller graph for this function:


Member Function Documentation

def string.Template._invalid (   self,
  mo 
) [private]

Definition at line 101 of file string.py.

00101 
00102     def _invalid(self, mo):
00103         i = mo.start('invalid')
00104         lines = self.template[:i].splitlines(True)
00105         if not lines:
00106             colno = 1
00107             lineno = 1
00108         else:
00109             colno = i - len(''.join(lines[:-1]))
00110             lineno = len(lines)
00111         raise ValueError('Invalid placeholder in string: line %d, col %d' %
00112                          (lineno, colno))

Here is the caller graph for this function:

def string.Template.safe_substitute (   self,
  args,
  kws 
)

Definition at line 139 of file string.py.

00139 
00140     def safe_substitute(self, *args, **kws):
00141         if len(args) > 1:
00142             raise TypeError('Too many positional arguments')
00143         if not args:
00144             mapping = kws
00145         elif kws:
00146             mapping = _multimap(kws, args[0])
00147         else:
00148             mapping = args[0]
00149         # Helper function for .sub()
00150         def convert(mo):
00151             named = mo.group('named') or mo.group('braced')
00152             if named is not None:
00153                 try:
00154                     # We use this idiom instead of str() because the latter
00155                     # will fail if val is a Unicode containing non-ASCII
00156                     return '%s' % (mapping[named],)
00157                 except KeyError:
00158                     return mo.group()
00159             if mo.group('escaped') is not None:
00160                 return self.delimiter
00161             if mo.group('invalid') is not None:
00162                 return mo.group()
00163             raise ValueError('Unrecognized named group in pattern',
00164                              self.pattern)
00165         return self.pattern.sub(convert, self.template)
00166 
00167 

Here is the call graph for this function:

def string.Template.substitute (   self,
  args,
  kws 
)

Definition at line 113 of file string.py.

00113 
00114     def substitute(self, *args, **kws):
00115         if len(args) > 1:
00116             raise TypeError('Too many positional arguments')
00117         if not args:
00118             mapping = kws
00119         elif kws:
00120             mapping = _multimap(kws, args[0])
00121         else:
00122             mapping = args[0]
00123         # Helper function for .sub()
00124         def convert(mo):
00125             # Check the most common path first.
00126             named = mo.group('named') or mo.group('braced')
00127             if named is not None:
00128                 val = mapping[named]
00129                 # We use this idiom instead of str() because the latter will
00130                 # fail if val is a Unicode containing non-ASCII characters.
00131                 return '%s' % (val,)
00132             if mo.group('escaped') is not None:
00133                 return self.delimiter
00134             if mo.group('invalid') is not None:
00135                 self._invalid(mo)
00136             raise ValueError('Unrecognized named group in pattern',
00137                              self.pattern)
00138         return self.pattern.sub(convert, self.template)

Here is the call graph for this function:


Member Data Documentation

string string.Template.delimiter = '$' [static]

Definition at line 92 of file string.py.

string.Template.flags = _re.IGNORECASE [static]

Definition at line 94 of file string.py.

string string.Template.idpattern = r'[_a-z][_a-z0-9]*' [static]

Definition at line 93 of file string.py.

string string._TemplateMetaclass.pattern = r"" [static, inherited]

Definition at line 68 of file string.py.

string.Template.template

Definition at line 97 of file string.py.


The documentation for this class was generated from the following file: