This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author paul.j3
Recipients bethard, paul.j3, petri.lehtinen, pwil3058
Date 2013-09-19.01:40:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1379554857.35.0.777539053411.issue11708@psf.upfronthosting.co.za>
In-reply-to
Content
This is a HelpFormatter function that takes a list of formatted actions, and groups contiguous blocks of optional positional actions.  It accounts for optionals (via prefix_chars) and mutually exclusive groups.

Since it assumes 'parts' is a list, rather than string, it works best with the '_format_actions_usage' method in the patch that I submitted to http://bugs.python.org/issue11874 

    def _positionals_regroup(self, parts):
        # change '[arg1] [arg2]' to '[arg1 [arg2]]'
        # apply to a list of formatted arguments
        # don't apply to optionals (with prefix chars) or groups
        chars = getattr(self, 'prefix_chars',set('-'))
        R = _re.compile(r'\] \[(.*)\]')
        result = []
        text = None
        while  parts:
            part = parts.pop()
            if part:
                if part[0]=='[' and part[1] not in chars and '|' not in part:
                    if text:
                        text = ' '.join([part, text])
                    else:
                        text = part
                    if R.search(text):
                        text = R.sub(' [\g<1>]]',text)
                else:
                    if text:
                        result.insert(0,text)
                        text = None
                    result.insert(0,part)
        if text:
            result.insert(0,text)
        return result

To avoid compatibility issues it could implemented in a subclassed HelpFormatter.
History
Date User Action Args
2013-09-19 01:40:57paul.j3setrecipients: + paul.j3, bethard, pwil3058, petri.lehtinen
2013-09-19 01:40:57paul.j3setmessageid: <1379554857.35.0.777539053411.issue11708@psf.upfronthosting.co.za>
2013-09-19 01:40:57paul.j3linkissue11708 messages
2013-09-19 01:40:56paul.j3create