From ac20f57c2810ad980953d6d8f65fb6f3e2c6c741 Mon Sep 17 00:00:00 2001 From: Edward Loper Date: Thu, 12 Aug 2004 02:02:24 +0000 Subject: [PATCH] - Added a register_optionflag function (so users can add their own option flags); and use it to define the existing optionflag constants. --- Lib/doctest.py | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/Lib/doctest.py b/Lib/doctest.py index 7c07131676a..31c0af8d6e0 100644 --- a/Lib/doctest.py +++ b/Lib/doctest.py @@ -193,28 +193,6 @@ from StringIO import StringIO real_pdb_set_trace = pdb.set_trace -# Option constants. -DONT_ACCEPT_TRUE_FOR_1 = 1 << 0 -DONT_ACCEPT_BLANKLINE = 1 << 1 -NORMALIZE_WHITESPACE = 1 << 2 -ELLIPSIS = 1 << 3 -UNIFIED_DIFF = 1 << 4 -CONTEXT_DIFF = 1 << 5 - -OPTIONFLAGS_BY_NAME = { - 'DONT_ACCEPT_TRUE_FOR_1': DONT_ACCEPT_TRUE_FOR_1, - 'DONT_ACCEPT_BLANKLINE': DONT_ACCEPT_BLANKLINE, - 'NORMALIZE_WHITESPACE': NORMALIZE_WHITESPACE, - 'ELLIPSIS': ELLIPSIS, - 'UNIFIED_DIFF': UNIFIED_DIFF, - 'CONTEXT_DIFF': CONTEXT_DIFF, - } - -# Special string markers for use in `want` strings: -BLANKLINE_MARKER = '' -ELLIPSIS_MARKER = '...' - - # There are 4 basic classes: # - Example: a pair, plus an intra-docstring line number. # - DocTest: a collection of examples, parsed from a docstring, plus @@ -234,6 +212,24 @@ ELLIPSIS_MARKER = '...' # | Example | # +---------+ +# Option constants. +OPTIONFLAGS_BY_NAME = {} +def register_optionflag(name): + flag = 1 << len(OPTIONFLAGS_BY_NAME) + OPTIONFLAGS_BY_NAME[name] = flag + return flag + +DONT_ACCEPT_TRUE_FOR_1 = register_optionflag('DONT_ACCEPT_TRUE_FOR_1') +DONT_ACCEPT_BLANKLINE = register_optionflag('DONT_ACCEPT_BLANKLINE') +NORMALIZE_WHITESPACE = register_optionflag('NORMALIZE_WHITESPACE') +ELLIPSIS = register_optionflag('ELLIPSIS') +UNIFIED_DIFF = register_optionflag('UNIFIED_DIFF') +CONTEXT_DIFF = register_optionflag('CONTEXT_DIFF') + +# Special string markers for use in `want` strings: +BLANKLINE_MARKER = '' +ELLIPSIS_MARKER = '...' + ###################################################################### ## Table of Contents ######################################################################