Back to index

python3.2  3.2.2
Public Member Functions | Private Member Functions
string.Formatter Class Reference

List of all members.

Public Member Functions

def format
def vformat
def get_value
def check_unused_args
def format_field
def convert_field
def parse
def get_field

Private Member Functions

def _vformat

Detailed Description

Definition at line 178 of file string.py.


Member Function Documentation

def string.Formatter._vformat (   self,
  format_string,
  args,
  kwargs,
  used_args,
  recursion_depth 
) [private]

Definition at line 188 of file string.py.

00188 
00189     def _vformat(self, format_string, args, kwargs, used_args, recursion_depth):
00190         if recursion_depth < 0:
00191             raise ValueError('Max string recursion exceeded')
00192         result = []
00193         for literal_text, field_name, format_spec, conversion in \
00194                 self.parse(format_string):
00195 
00196             # output the literal text
00197             if literal_text:
00198                 result.append(literal_text)
00199 
00200             # if there's a field, output it
00201             if field_name is not None:
00202                 # this is some markup, find the object and do
00203                 #  the formatting
00204 
00205                 # given the field_name, find the object it references
00206                 #  and the argument it came from
00207                 obj, arg_used = self.get_field(field_name, args, kwargs)
00208                 used_args.add(arg_used)
00209 
00210                 # do any conversion on the resulting object
00211                 obj = self.convert_field(obj, conversion)
00212 
00213                 # expand the format spec, if needed
00214                 format_spec = self._vformat(format_spec, args, kwargs,
00215                                             used_args, recursion_depth-1)
00216 
00217                 # format the object and append to the result
00218                 result.append(self.format_field(obj, format_spec))
00219 
00220         return ''.join(result)
00221 

Here is the call graph for this function:

Here is the caller graph for this function:

def string.Formatter.check_unused_args (   self,
  used_args,
  args,
  kwargs 
)

Definition at line 229 of file string.py.

00229 
00230     def check_unused_args(self, used_args, args, kwargs):
00231         pass
00232 

Here is the caller graph for this function:

def string.Formatter.convert_field (   self,
  value,
  conversion 
)

Definition at line 237 of file string.py.

00237 
00238     def convert_field(self, value, conversion):
00239         # do any conversion on the resulting object
00240         if conversion == 'r':
00241             return repr(value)
00242         elif conversion == 's':
00243             return str(value)
00244         elif conversion is None:
00245             return value
00246         raise ValueError("Unknown conversion specifier {0!s}".format(conversion))
00247 

Here is the caller graph for this function:

def string.Formatter.format (   self,
  format_string,
  args,
  kwargs 
)

Definition at line 179 of file string.py.

00179 
00180     def format(self, format_string, *args, **kwargs):
00181         return self.vformat(format_string, args, kwargs)

Here is the call graph for this function:

Here is the caller graph for this function:

def string.Formatter.format_field (   self,
  value,
  format_spec 
)

Definition at line 233 of file string.py.

00233 
00234     def format_field(self, value, format_spec):
00235         return format(value, format_spec)
00236 

Here is the caller graph for this function:

def string.Formatter.get_field (   self,
  field_name,
  args,
  kwargs 
)

Definition at line 264 of file string.py.

00264 
00265     def get_field(self, field_name, args, kwargs):
00266         first, rest = _string.formatter_field_name_split(field_name)
00267 
00268         obj = self.get_value(first, args, kwargs)
00269 
00270         # loop through the rest of the field_name, doing
00271         #  getattr or getitem as needed
00272         for is_attr, i in rest:
00273             if is_attr:
00274                 obj = getattr(obj, i)
00275             else:
00276                 obj = obj[i]
00277 
00278         return obj, first

Here is the call graph for this function:

Here is the caller graph for this function:

def string.Formatter.get_value (   self,
  key,
  args,
  kwargs 
)

Definition at line 222 of file string.py.

00222 
00223     def get_value(self, key, args, kwargs):
00224         if isinstance(key, int):
00225             return args[key]
00226         else:
00227             return kwargs[key]
00228 

Here is the call graph for this function:

Here is the caller graph for this function:

def string.Formatter.parse (   self,
  format_string 
)

Definition at line 255 of file string.py.

00255 
00256     def parse(self, format_string):
00257         return _string.formatter_parser(format_string)
00258 

Here is the call graph for this function:

Here is the caller graph for this function:

def string.Formatter.vformat (   self,
  format_string,
  args,
  kwargs 
)

Definition at line 182 of file string.py.

00182 
00183     def vformat(self, format_string, args, kwargs):
00184         used_args = set()
00185         result = self._vformat(format_string, args, kwargs, used_args, 2)
00186         self.check_unused_args(used_args, args, kwargs)
00187         return result

Here is the call graph for this function:

Here is the caller graph for this function:


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