From 77bef10fa6bce063445df4feb9ac5f678b71cb99 Mon Sep 17 00:00:00 2001 Message-Id: <77bef10fa6bce063445df4feb9ac5f678b71cb99.1714065141.git.mdw@distorted.org.uk> From: Mark Wooding Date: Sat, 16 Mar 2013 17:28:37 +0000 Subject: [PATCH] format.py: Allow general format controls more widely. Organization: Straylight/Edgeware From: Mark Wooding In particular, allow them as inputs to `compile', and to the `~{~}' and `~?' directives. --- format.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/format.py b/format.py index 7b5d93c..d6eb896 100644 --- a/format.py +++ b/format.py @@ -812,6 +812,7 @@ def compile(control): notation indicates which argument(s) should be processed by the operation: the default is `=+'. """ + if not isinstance(control, basestring): return control pp = [] with COMPILE.bind(control = control, start = 0, end = len(control), delim = ''): @@ -872,10 +873,7 @@ def format(out, control, *args, **kw): raise TypeError, out ## Turn the control argument into a formatting operation. - if isinstance(control, basestring): - op = compile(control) - else: - op = control + op = compile(control) ## Invoke the formatting operation in the correct environment. with FORMAT.bind(write = write, pushback = [], @@ -1260,7 +1258,7 @@ class FormatIteration (BaseFormatOperation): then the enclosed directives are applied once even if the argument sequence is empty. - If the formatting directives are empty then a formatting string is fetched + If the formatting directives are empty then a formatting control is fetched using the argument collector associated with the closing delimiter. """ @@ -1349,7 +1347,7 @@ class FormatRecursive (BaseFormatOperation): """ ~?: Recursive formatting. - Without `@', read a pair of arguments: use the first as a format string, + Without `@', read a pair of arguments: use the first as a format control, and apply it to the arguments extracted from the second (which may be a sequence or a map). -- [mdw]