| 1 |
""" |
| 2 |
Module demonstrating the constant representations. |
| 3 |
""" |
| 4 |
|
| 5 |
import re |
| 6 |
from .demo_restructuredtext_module import demo_fields_docstring_arguments, _PrivateClass |
| 7 |
|
| 8 |
A_DICT = {'1':33, '2':[1,2,3,{7:'oo'*20}], |
| 9 |
'3': demo_fields_docstring_arguments, |
| 10 |
'4': _PrivateClass.method_inside_private, |
| 11 |
'5': re.compile('^<(?P<descr>.*) at (?P<addr>0x[0-9a-f]+)>$') } |
| 12 |
""" |
| 13 |
The value of a constant is rendered with syntax highlighting. |
| 14 |
Internal and external links are generated to references of classes/functions used inside the constant |
| 15 |
""" |
| 16 |
|
| 17 |
A_STIRNG = "L'humour, c'est l'arme blanche des hommes désarmés; c'est une déclaration de supériorité de l'humain sur ce qui lui arrive 😀. Romain GARY." |
| 18 |
""" |
| 19 |
Strings are always rendered in single quotes, and appropriate escaping is added when required. |
| 20 |
|
| 21 |
Continuing lines are wrapped with symbol: "↵" after reaching the maximum number of caracters per line (defaults to 80), change this value with option --pyval-repr-linelen. |
| 22 |
|
| 23 |
Unicode is supported. |
| 24 |
""" |
| 25 |
|
| 26 |
A_MULTILINE_STRING = "Dieu se rit des hommes qui déplorent les effets dont ils cherrissent les causes.\n\nJacques-Bénigne BOSSUET." |
| 27 |
""" |
| 28 |
Multiline strings are always rendered in triple quotes. |
| 29 |
""" |
| 30 |
|
| 31 |
A_LIST = [1,2,[5,6,[(11,22,33),9],10],11]+[99,98,97,96,95] |
| 32 |
""" |
| 33 |
Nested objects are colorized. |
| 34 |
""" |
| 35 |
|
| 36 |
FUNCTION_CALL = list(range(100))+[99,98,97,96,95] |
| 37 |
""" |
| 38 |
Function calls are colorized. |
| 39 |
""" |
| 40 |
|
| 41 |
OPERATORS = 1 << (10 | 1) << 1 |
| 42 |
"""Operators are colorized and parenthesis are added when syntactically required.""" |
| 43 |
|
| 44 |
UNSUPPORTED = lambda x: demo_fields_docstring_arguments(x, 0) // 2 |
| 45 |
""" |
| 46 |
A lot of objects can be colorized: function calls, strings, lists, dicts, sets, frozensets, operators, annotations, names, compiled regular expressions, etc. |
| 47 |
But when dealing with usupported constructs, like lamba functions, it will display the value without colorization. |
| 48 |
""" |
| 49 |
|
| 50 |
RE_STR = re.compile("(foo (?P<a>bar) | (?P<boop>baz))") |
| 51 |
""" |
| 52 |
Regular expressions have special colorizing that add syntax highlight to the regex components. |
| 53 |
""" |
| 54 |
|
| 55 |
RE_WITH_UNICODE = re.compile("abc 😀") |
| 56 |
""" |
| 57 |
Unicode is supported in regular expressions. |
| 58 |
""" |
| 59 |
|
| 60 |
RE_MULTILINE = re.compile(r''' |
| 61 |
# Source consists of a PS1 line followed by zero or more PS2 lines. |
| 62 |
(?P<source> |
| 63 |
(?:^(?P<indent> [ ]*) >>> .*) # PS1 line |
| 64 |
(?:\n [ ]* \.\.\. .*)* # PS2 lines |
| 65 |
\n?) |
| 66 |
# Want consists of any non-blank lines that do not start with PS1. |
| 67 |
(?P<want> (?:(?![ ]*$) # Not a blank line |
| 68 |
(?![ ]*>>>) # Not a line starting with PS1 |
| 69 |
.*$\n? # But any other line |
| 70 |
)*) |
| 71 |
''', re.MULTILINE | re.VERBOSE) |
| 72 |
""" |
| 73 |
Multiline regex patterns are rendered as string. |
| 74 |
|
| 75 |
"..." is added when reaching the maximum number of lines for constant representation (defaults to 7), change this value with option --pyval-repr-maxlines. |
| 76 |
""" |