Opened 4 years ago

Closed 4 years ago

#6063 enhancement closed fixed (fixed)

Support arbitrary formatting helpers in FancyStrMixin

Reported by: Jean-Paul Calderone Owned by: Jean-Paul Calderone
Priority: normal Milestone: Python 3.3 Minimal
Component: core Keywords:
Cc: Branch: branches/fancyfancystrmixin-6063-2
branch-diff, diff-cov, branch-cov, buildbot
Author: exarkun

Description

FancyStrMixin supports the printf-style string formatting specification for controlling how attributes are displayed. This is handy, but printf-style only goes so far. For example, on Python 3, there is no printf-style formatter which operates on bytes instance to produce a "foo\x00"-style output (%s comes with an unwanted b prefix).

Allowing a formatting function to be supplied would let applications format things any way they wish. This is most directly needed by #6057, but is probably more widely useful.

Change History (6)

comment:1 Changed 4 years ago by Jean-Paul Calderone

Author: exarkun
Branch: branches/fancyfancystrmixin-6063

(In [35958]) Branching to 'fancyfancystrmixin-6063'

comment:2 Changed 4 years ago by Jean-Paul Calderone

Branch: branches/fancyfancystrmixin-6063branches/fancyfancystrmixin-6063-2

(In [35960]) Branching to 'fancyfancystrmixin-6063-2'

comment:3 Changed 4 years ago by Jean-Paul Calderone

(In [35961]) Support a callable to format attribute values

refs #6063

comment:4 Changed 4 years ago by Jean-Paul Calderone

Keywords: review added
Owner: changed from Jean-Paul Calderone to Itamar Turner-Trauring

comment:5 Changed 4 years ago by Itamar Turner-Trauring

Keywords: review removed
Owner: changed from Itamar Turner-Trauring to Jean-Paul Calderone

Sigh. This is turning into an (even more) terrible API. I'm sure we can come up with a new, cleaner approach in our copious spare time. Meanwhile, this seems reasonable, please merge.

comment:6 Changed 4 years ago by Jean-Paul Calderone

Resolution: fixed
Status: newclosed

(In [35964]) Merge fancyfancystrmixin-6063-2

Author: exarkun Reviewer: itamarst Fixes: #6063

Add more flexibility to the formatting done by twisted.python.util.FancyStrMixin by supporting arbitrary callables to format attribute values.

Note: See TracTickets for help on using tickets.