cengal.code_inspection.auto_line_tracer.versions.v_0.auto_line_tracer

  1#!/usr/bin/env python
  2# coding=utf-8
  3
  4# Copyright © 2012-2024 ButenkoMS. All rights reserved. Contacts: <gtalk@butenkoms.space>
  5# 
  6# Licensed under the Apache License, Version 2.0 (the "License");
  7# you may not use this file except in compliance with the License.
  8# You may obtain a copy of the License at
  9# 
 10#     http://www.apache.org/licenses/LICENSE-2.0
 11# 
 12# Unless required by applicable law or agreed to in writing, software
 13# distributed under the License is distributed on an "AS IS" BASIS,
 14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15# See the License for the specific language governing permissions and
 16# limitations under the License.
 17
 18from cengal.code_inspection.line_tracer import LineTracer
 19from cengal.data_generation.id_generator import IDGenerator
 20from cengal.introspection.inspect import intro_func_repr, intro_func_repr_limited, get_multistr_of_data_value
 21from enum import Enum, IntEnum
 22from typing import Callable, Optional, Any, Set
 23try:
 24    import rich
 25    RICH_PRESENT = True
 26except ImportError:
 27    RICH_PRESENT = False
 28
 29"""
 30Module Docstring
 31Docstrings: http://www.python.org/dev/peps/pep-0257/
 32"""
 33
 34__author__ = "ButenkoMS <gtalk@butenkoms.space>"
 35__copyright__ = "Copyright © 2012-2024 ButenkoMS. All rights reserved. Contacts: <gtalk@butenkoms.space>"
 36__credits__ = ["ButenkoMS <gtalk@butenkoms.space>", ]
 37__license__ = "Apache License, Version 2.0"
 38__version__ = "4.4.1"
 39__maintainer__ = "ButenkoMS <gtalk@butenkoms.space>"
 40__email__ = "gtalk@butenkoms.space"
 41# __status__ = "Prototype"
 42__status__ = "Development"
 43# __status__ = "Production"
 44
 45
 46class CodeStartReplType(IntEnum):
 47    general = 0
 48    general_verbose = 1
 49    limited = 2
 50    limited_verbose = 3
 51
 52
 53class LineType(IntEnum):
 54    previous_line = 0
 55    current_line = 1
 56    next_line = 2
 57    exact_line = 3
 58    relative_line = 4
 59
 60
 61class OutputFields(IntEnum):
 62    trace_name = 0
 63    file_name = 1
 64    line = 2
 65    func_name = 3
 66    code_line = 4
 67    result = 5
 68    new_line_after_end = 6
 69    start_short_name = 7
 70
 71
 72class AutoLineTracer:
 73    def __init__(self, code_start_repl_type: CodeStartReplType = CodeStartReplType.general, print_allowed: bool = True, rich_allowed: bool = True, *args, **kwargs):
 74        self.code_start_repl_type: CodeStartReplType = code_start_repl_type
 75        self.print_allowed: bool = print_allowed
 76        self.rich_allowed: bool = rich_allowed
 77        if CodeStartReplType.general == code_start_repl_type:
 78            self.code_start_repl = self._start_impl_general
 79        elif CodeStartReplType.general_verbose == code_start_repl_type:
 80            self.code_start_repl = self._start_impl_general_verbose
 81        elif CodeStartReplType.limited == code_start_repl_type:
 82            self.code_start_repl = self._start_impl_limited
 83        elif CodeStartReplType.limited_verbose == code_start_repl_type:
 84            self.code_start_repl = self._start_impl_limited_verbose
 85        
 86        self.lt: LineTracer = LineTracer(*args, **kwargs)
 87        self._index: IDGenerator = IDGenerator()
 88        self.line_template: str = '#{index:<4n}| <[{name}]> | <file \'{file_name}\' line {line}>.{func_name}()\n\t| {code_line}'
 89        self.line_template_name_less: str = '#{index:<4n}| <file \'{file_name}\' line {line}>.{func_name}()\n\t| {code_line}'
 90        # self.start_template: str = '#{index:<4n}| <+[{name}]+>'
 91        self.start_template: str = '#{index:<4n}| <+[{short_name}]+>\n\t|<+[{name}]+>'
 92        self.end_template: str = '#{index:<4n}| <-[{short_name}]->\n\t|<-[{name}]->'
 93
 94        self.s = self.start
 95        self.e = self.end
 96        self.p = self.previous_line
 97        self.c = self.current_line
 98        self.n = self.next_line
 99
100        self.ps = self.print_start
101        self.pe = self.print_end
102        self.pp = self.print_previous_line
103        self.pc = self.print_current_line
104        self.pcptv = self.print_current_line_pp_type_value
105        self.pcpt = self.print_current_line_pp_value
106        self.pn = self.print_next_line
107    
108    @property
109    def index(self):
110        return self._index()
111
112    def _start_impl_general(self, depth: int = 1):
113        return intro_func_repr(False, depth + 1)
114
115    def _start_impl_general_verbose(self, depth: int = 1):
116        return intro_func_repr(True, depth + 1)
117
118    def _start_impl_limited(self, depth: int = 1):
119        return intro_func_repr_limited(False, depth + 1)
120
121    def _start_impl_limited_verbose(self, depth: int = 1):
122        return intro_func_repr_limited(True, depth + 1)
123    
124    def start(self, depth: int = 1):
125        short_name = self._start_impl_limited(depth + 1)
126        name = self.code_start_repl(depth + 1)
127        return self.start_template.format(index=self.index, short_name=short_name, name=name)
128
129    def print_start(self, depth: int = 1):
130        if self.print_allowed:
131            print(self.start(depth + 1) + '\n')
132
133    def end(self, depth: int = 1):
134        short_name = self._start_impl_limited(depth + 1)
135        name = self.code_start_repl(depth + 1)
136        return self.end_template.format(index=self.index, short_name=short_name, name=name)
137
138    def print_end(self, depth: int = 1):
139        if self.print_allowed:
140            print(self.end(depth + 1) + '\n')
141
142    def previous_line(self, name: Optional[str] = None, depth: int = 1):
143        filename, function_name, line_number, lines, index = self.lt.trace(depth + 1)
144        lines = lines.strip()
145        if name is None:
146            return self.line_template_name_less.format(index=self.index, file_name=filename, line=line_number, func_name=function_name, code_line=lines)
147        else:
148            return self.line_template.format(index=self.index, name=name, file_name=filename, line=line_number, func_name=function_name, code_line=lines)
149
150    def print_previous_line(self, name: Optional[str] = None, depth: int = 1):
151        if self.print_allowed:
152            print(self.previous_line(name, depth + 1) + '\n')
153
154    def current_line(self, line_result, name: Optional[str] = None, line_type: LineType = LineType.current_line, line_num: Optional[int] = None, 
155                     output_fields: Optional[Set[OutputFields]] = None, 
156                     depth: int = 1):
157        if output_fields is None:
158            output_fields = {
159                OutputFields.trace_name, 
160                OutputFields.file_name,
161                OutputFields.line,
162                OutputFields.func_name,
163                OutputFields.code_line,
164                OutputFields.result,
165            }
166
167        if LineType.current_line == line_type:
168            filename, function_name, line_number, lines, index = self.lt.trace_self(depth + 1)
169        elif LineType.exact_line == line_type:
170            filename, function_name, line_number, lines, index = self.lt.trace_exact(line_num, depth + 1)
171        elif LineType.relative_line == line_type:
172            filename, function_name, line_number, lines, index = self.lt.trace_relative(line_num, depth + 1)
173        elif LineType.previous_line == line_type:
174            filename, function_name, line_number, lines, index = self.lt.trace(depth + 1)
175        elif LineType.next_line == line_type:
176            filename, function_name, line_number, lines, index = self.lt.trace_next(depth + 1)
177
178        lines = lines.strip()
179        if name is None:
180            result = self.line_template_name_less.format(index=self.index, file_name=filename, line=line_number, func_name=function_name, code_line=lines)
181        else:
182            result = self.line_template.format(index=self.index, name=name, file_name=filename, line=line_number, func_name=function_name, code_line=lines)
183        
184        if OutputFields.result in output_fields:
185            result += f'\n\t\t| {line_result}'
186        
187        return result
188
189    def print_current_line(self, line_result, name: Optional[str] = None, line_type: LineType = LineType.current_line, line_num: Optional[int] = None, output_fields: Optional[Set[OutputFields]] = None, depth: int = 1) -> Any:
190        if output_fields is None:
191            output_fields = {
192                OutputFields.trace_name, 
193                OutputFields.file_name,
194                OutputFields.line,
195                OutputFields.func_name,
196                OutputFields.code_line,
197                OutputFields.result,
198                OutputFields.new_line_after_end,
199            }
200
201        if self.print_allowed:
202            if RICH_PRESENT and self.rich_allowed:
203                from rich.console import Console
204                from rich.syntax import Syntax
205
206                if LineType.current_line == line_type:
207                    filename, function_name, line_number, lines, index = self.lt.trace_self(depth + 1)
208                elif LineType.exact_line == line_type:
209                    filename, function_name, line_number, lines, index = self.lt.trace_exact(line_num, depth + 1)
210                elif LineType.relative_line == line_type:
211                    filename, function_name, line_number, lines, index = self.lt.trace_relative(line_num, depth + 1)
212                elif LineType.previous_line == line_type:
213                    filename, function_name, line_number, lines, index = self.lt.trace(depth + 1)
214                elif LineType.next_line == line_type:
215                    filename, function_name, line_number, lines, index = self.lt.trace_next(depth + 1)
216
217                # lines = lines.strip()
218                syntax = Syntax(lines, "python", theme="monokai", line_numbers=True, start_line=line_number)
219                console = Console()
220                cl = self.current_line(line_result, name, line_type, line_num, output_fields, depth + 1)
221                clines = cl.split('\n')
222                # print(clines[0])
223                console.print(clines[0])
224                console.print(syntax)
225                clines_rest = clines[2:]
226                for cline in clines_rest:
227                    console.print(cline)
228                
229                if OutputFields.new_line_after_end in output_fields:
230                    print()
231                    # console.print(clines[3])
232                    # print(clines[2])
233            else:
234                if OutputFields.new_line_after_end in output_fields:
235                    ending = '\n'
236                else:
237                    ending = ''
238
239                print(self.current_line(line_result, name, line_type, line_num, output_fields, depth + 1) + ending)
240        
241        return line_result
242
243    def print_current_line_pp_type_value(self, line_result, name: Optional[str] = None, line_type: LineType = LineType.current_line, line_num: Optional[int] = None, output_fields: Optional[Set[OutputFields]] = None, depth: int = 1) -> Any:
244        multistr_data_value: str = get_multistr_of_data_value(line_result, 3).lstrip(' \t')
245        str_template = f'{type(line_result)}\n\t\t| {multistr_data_value}'
246        self.print_current_line(str_template, name, line_type, line_num, output_fields, depth + 1)
247        return line_result
248
249    def print_current_line_pp_value(self, line_result, name: Optional[str] = None, line_type: LineType = LineType.current_line, line_num: Optional[int] = None, output_fields: Optional[Set[OutputFields]] = None, depth: int = 1) -> Any:
250        str_template = get_multistr_of_data_value(line_result, 3).lstrip(' \t')
251        self.print_current_line(str_template, name, line_type, line_num, output_fields, depth + 1)
252        return line_result
253    
254    def next_line(self, name: Optional[str] = None, depth: int = 1):
255        filename, function_name, line_number, lines, index = self.lt.trace_next(depth + 1)
256        lines = lines.strip()
257        if name is None:
258            return self.line_template_name_less.format(index=self.index, file_name=filename, line=line_number, func_name=function_name, code_line=lines)
259        else:
260            return self.line_template.format(index=self.index, name=name, file_name=filename, line=line_number, func_name=function_name, code_line=lines)
261
262    def print_next_line(self, name: Optional[str] = None, depth: int = 1):
263        if self.print_allowed:
264            print(self.next_line(name, depth + 1) + '\n')
265    
266    def __call__(self, depth: int = 1):
267        _, _, prev_line_number, prev_lines, _ = self.lt.trace(depth + 1)
268        filename, function_name, next_line_number, next_lines, _ = self.lt.trace_next(depth + 1)
269        return filename, function_name, prev_line_number, next_line_number, prev_lines, next_lines
270
271
272auto_line_tracer__general = AutoLineTracer(CodeStartReplType.general)
273auto_line_tracer__general_verbose = AutoLineTracer(CodeStartReplType.general_verbose)
274auto_line_tracer__limited = AutoLineTracer(CodeStartReplType.limited)
275auto_line_tracer__limited_verbose = AutoLineTracer(CodeStartReplType.limited_verbose)
276
277altg = auto_line_tracer__general
278altgv = auto_line_tracer__general_verbose
279altl = auto_line_tracer__limited
280altlv = auto_line_tracer__limited_verbose
281
282alt = altg
283
284
285def trace_self__general(line_result, name: Optional[str] = None, line_type: LineType = LineType.current_line, line_num: Optional[int] = None, output_fields: Optional[Set[OutputFields]] = None, depth: int = 1) -> Any:
286    return auto_line_tracer__general.print_current_line_pp_type_value(line_result, name, line_type, line_num, output_fields, depth + 1)
287
288
289def trace_self__general_verbose(line_result, name: Optional[str] = None, line_type: LineType = LineType.current_line, line_num: Optional[int] = None, output_fields: Optional[Set[OutputFields]] = None, depth: int = 1) -> Any:
290    return auto_line_tracer__general_verbose.print_current_line_pp_type_value(line_result, name, line_type, line_num, output_fields, depth + 1)
291
292
293def trace_self__limited(line_result, name: Optional[str] = None, line_type: LineType = LineType.current_line, line_num: Optional[int] = None, output_fields: Optional[Set[OutputFields]] = None, depth: int = 1) -> Any:
294    return auto_line_tracer__limited.print_current_line_pp_type_value(line_result, name, line_type, line_num, output_fields, depth + 1)
295
296
297def trace_self__limited_verbose(line_result, name: Optional[str] = None, line_type: LineType = LineType.current_line, line_num: Optional[int] = None, output_fields: Optional[Set[OutputFields]] = None, depth: int = 1) -> Any:
298    return auto_line_tracer__limited_verbose.print_current_line_pp_type_value(line_result, name, line_type, line_num, output_fields, depth + 1)
299
300
301tsg = trace_self__general
302tsgv = trace_self__general_verbose
303tsl = trace_self__limited
304tslv = trace_self__limited_verbose
305
306ts = tsg
307
308
309def fake_trace_self(line_result, name: Optional[str] = None, line_type: LineType = LineType.current_line, line_num: Optional[int] = None, output_fields: Optional[Set[OutputFields]] = None, depth: int = 1):
310    return line_result
311
312
313fts = fake_trace_self
class CodeStartReplType(enum.IntEnum):
47class CodeStartReplType(IntEnum):
48    general = 0
49    general_verbose = 1
50    limited = 2
51    limited_verbose = 3

An enumeration.

general = <CodeStartReplType.general: 0>
general_verbose = <CodeStartReplType.general_verbose: 1>
limited = <CodeStartReplType.limited: 2>
limited_verbose = <CodeStartReplType.limited_verbose: 3>
Inherited Members
enum.Enum
name
value
builtins.int
conjugate
bit_length
to_bytes
from_bytes
as_integer_ratio
real
imag
numerator
denominator
class LineType(enum.IntEnum):
54class LineType(IntEnum):
55    previous_line = 0
56    current_line = 1
57    next_line = 2
58    exact_line = 3
59    relative_line = 4

An enumeration.

previous_line = <LineType.previous_line: 0>
current_line = <LineType.current_line: 1>
next_line = <LineType.next_line: 2>
exact_line = <LineType.exact_line: 3>
relative_line = <LineType.relative_line: 4>
Inherited Members
enum.Enum
name
value
builtins.int
conjugate
bit_length
to_bytes
from_bytes
as_integer_ratio
real
imag
numerator
denominator
class OutputFields(enum.IntEnum):
62class OutputFields(IntEnum):
63    trace_name = 0
64    file_name = 1
65    line = 2
66    func_name = 3
67    code_line = 4
68    result = 5
69    new_line_after_end = 6
70    start_short_name = 7

An enumeration.

trace_name = <OutputFields.trace_name: 0>
file_name = <OutputFields.file_name: 1>
line = <OutputFields.line: 2>
func_name = <OutputFields.func_name: 3>
code_line = <OutputFields.code_line: 4>
result = <OutputFields.result: 5>
new_line_after_end = <OutputFields.new_line_after_end: 6>
start_short_name = <OutputFields.start_short_name: 7>
Inherited Members
enum.Enum
name
value
builtins.int
conjugate
bit_length
to_bytes
from_bytes
as_integer_ratio
real
imag
numerator
denominator
class AutoLineTracer:
 73class AutoLineTracer:
 74    def __init__(self, code_start_repl_type: CodeStartReplType = CodeStartReplType.general, print_allowed: bool = True, rich_allowed: bool = True, *args, **kwargs):
 75        self.code_start_repl_type: CodeStartReplType = code_start_repl_type
 76        self.print_allowed: bool = print_allowed
 77        self.rich_allowed: bool = rich_allowed
 78        if CodeStartReplType.general == code_start_repl_type:
 79            self.code_start_repl = self._start_impl_general
 80        elif CodeStartReplType.general_verbose == code_start_repl_type:
 81            self.code_start_repl = self._start_impl_general_verbose
 82        elif CodeStartReplType.limited == code_start_repl_type:
 83            self.code_start_repl = self._start_impl_limited
 84        elif CodeStartReplType.limited_verbose == code_start_repl_type:
 85            self.code_start_repl = self._start_impl_limited_verbose
 86        
 87        self.lt: LineTracer = LineTracer(*args, **kwargs)
 88        self._index: IDGenerator = IDGenerator()
 89        self.line_template: str = '#{index:<4n}| <[{name}]> | <file \'{file_name}\' line {line}>.{func_name}()\n\t| {code_line}'
 90        self.line_template_name_less: str = '#{index:<4n}| <file \'{file_name}\' line {line}>.{func_name}()\n\t| {code_line}'
 91        # self.start_template: str = '#{index:<4n}| <+[{name}]+>'
 92        self.start_template: str = '#{index:<4n}| <+[{short_name}]+>\n\t|<+[{name}]+>'
 93        self.end_template: str = '#{index:<4n}| <-[{short_name}]->\n\t|<-[{name}]->'
 94
 95        self.s = self.start
 96        self.e = self.end
 97        self.p = self.previous_line
 98        self.c = self.current_line
 99        self.n = self.next_line
100
101        self.ps = self.print_start
102        self.pe = self.print_end
103        self.pp = self.print_previous_line
104        self.pc = self.print_current_line
105        self.pcptv = self.print_current_line_pp_type_value
106        self.pcpt = self.print_current_line_pp_value
107        self.pn = self.print_next_line
108    
109    @property
110    def index(self):
111        return self._index()
112
113    def _start_impl_general(self, depth: int = 1):
114        return intro_func_repr(False, depth + 1)
115
116    def _start_impl_general_verbose(self, depth: int = 1):
117        return intro_func_repr(True, depth + 1)
118
119    def _start_impl_limited(self, depth: int = 1):
120        return intro_func_repr_limited(False, depth + 1)
121
122    def _start_impl_limited_verbose(self, depth: int = 1):
123        return intro_func_repr_limited(True, depth + 1)
124    
125    def start(self, depth: int = 1):
126        short_name = self._start_impl_limited(depth + 1)
127        name = self.code_start_repl(depth + 1)
128        return self.start_template.format(index=self.index, short_name=short_name, name=name)
129
130    def print_start(self, depth: int = 1):
131        if self.print_allowed:
132            print(self.start(depth + 1) + '\n')
133
134    def end(self, depth: int = 1):
135        short_name = self._start_impl_limited(depth + 1)
136        name = self.code_start_repl(depth + 1)
137        return self.end_template.format(index=self.index, short_name=short_name, name=name)
138
139    def print_end(self, depth: int = 1):
140        if self.print_allowed:
141            print(self.end(depth + 1) + '\n')
142
143    def previous_line(self, name: Optional[str] = None, depth: int = 1):
144        filename, function_name, line_number, lines, index = self.lt.trace(depth + 1)
145        lines = lines.strip()
146        if name is None:
147            return self.line_template_name_less.format(index=self.index, file_name=filename, line=line_number, func_name=function_name, code_line=lines)
148        else:
149            return self.line_template.format(index=self.index, name=name, file_name=filename, line=line_number, func_name=function_name, code_line=lines)
150
151    def print_previous_line(self, name: Optional[str] = None, depth: int = 1):
152        if self.print_allowed:
153            print(self.previous_line(name, depth + 1) + '\n')
154
155    def current_line(self, line_result, name: Optional[str] = None, line_type: LineType = LineType.current_line, line_num: Optional[int] = None, 
156                     output_fields: Optional[Set[OutputFields]] = None, 
157                     depth: int = 1):
158        if output_fields is None:
159            output_fields = {
160                OutputFields.trace_name, 
161                OutputFields.file_name,
162                OutputFields.line,
163                OutputFields.func_name,
164                OutputFields.code_line,
165                OutputFields.result,
166            }
167
168        if LineType.current_line == line_type:
169            filename, function_name, line_number, lines, index = self.lt.trace_self(depth + 1)
170        elif LineType.exact_line == line_type:
171            filename, function_name, line_number, lines, index = self.lt.trace_exact(line_num, depth + 1)
172        elif LineType.relative_line == line_type:
173            filename, function_name, line_number, lines, index = self.lt.trace_relative(line_num, depth + 1)
174        elif LineType.previous_line == line_type:
175            filename, function_name, line_number, lines, index = self.lt.trace(depth + 1)
176        elif LineType.next_line == line_type:
177            filename, function_name, line_number, lines, index = self.lt.trace_next(depth + 1)
178
179        lines = lines.strip()
180        if name is None:
181            result = self.line_template_name_less.format(index=self.index, file_name=filename, line=line_number, func_name=function_name, code_line=lines)
182        else:
183            result = self.line_template.format(index=self.index, name=name, file_name=filename, line=line_number, func_name=function_name, code_line=lines)
184        
185        if OutputFields.result in output_fields:
186            result += f'\n\t\t| {line_result}'
187        
188        return result
189
190    def print_current_line(self, line_result, name: Optional[str] = None, line_type: LineType = LineType.current_line, line_num: Optional[int] = None, output_fields: Optional[Set[OutputFields]] = None, depth: int = 1) -> Any:
191        if output_fields is None:
192            output_fields = {
193                OutputFields.trace_name, 
194                OutputFields.file_name,
195                OutputFields.line,
196                OutputFields.func_name,
197                OutputFields.code_line,
198                OutputFields.result,
199                OutputFields.new_line_after_end,
200            }
201
202        if self.print_allowed:
203            if RICH_PRESENT and self.rich_allowed:
204                from rich.console import Console
205                from rich.syntax import Syntax
206
207                if LineType.current_line == line_type:
208                    filename, function_name, line_number, lines, index = self.lt.trace_self(depth + 1)
209                elif LineType.exact_line == line_type:
210                    filename, function_name, line_number, lines, index = self.lt.trace_exact(line_num, depth + 1)
211                elif LineType.relative_line == line_type:
212                    filename, function_name, line_number, lines, index = self.lt.trace_relative(line_num, depth + 1)
213                elif LineType.previous_line == line_type:
214                    filename, function_name, line_number, lines, index = self.lt.trace(depth + 1)
215                elif LineType.next_line == line_type:
216                    filename, function_name, line_number, lines, index = self.lt.trace_next(depth + 1)
217
218                # lines = lines.strip()
219                syntax = Syntax(lines, "python", theme="monokai", line_numbers=True, start_line=line_number)
220                console = Console()
221                cl = self.current_line(line_result, name, line_type, line_num, output_fields, depth + 1)
222                clines = cl.split('\n')
223                # print(clines[0])
224                console.print(clines[0])
225                console.print(syntax)
226                clines_rest = clines[2:]
227                for cline in clines_rest:
228                    console.print(cline)
229                
230                if OutputFields.new_line_after_end in output_fields:
231                    print()
232                    # console.print(clines[3])
233                    # print(clines[2])
234            else:
235                if OutputFields.new_line_after_end in output_fields:
236                    ending = '\n'
237                else:
238                    ending = ''
239
240                print(self.current_line(line_result, name, line_type, line_num, output_fields, depth + 1) + ending)
241        
242        return line_result
243
244    def print_current_line_pp_type_value(self, line_result, name: Optional[str] = None, line_type: LineType = LineType.current_line, line_num: Optional[int] = None, output_fields: Optional[Set[OutputFields]] = None, depth: int = 1) -> Any:
245        multistr_data_value: str = get_multistr_of_data_value(line_result, 3).lstrip(' \t')
246        str_template = f'{type(line_result)}\n\t\t| {multistr_data_value}'
247        self.print_current_line(str_template, name, line_type, line_num, output_fields, depth + 1)
248        return line_result
249
250    def print_current_line_pp_value(self, line_result, name: Optional[str] = None, line_type: LineType = LineType.current_line, line_num: Optional[int] = None, output_fields: Optional[Set[OutputFields]] = None, depth: int = 1) -> Any:
251        str_template = get_multistr_of_data_value(line_result, 3).lstrip(' \t')
252        self.print_current_line(str_template, name, line_type, line_num, output_fields, depth + 1)
253        return line_result
254    
255    def next_line(self, name: Optional[str] = None, depth: int = 1):
256        filename, function_name, line_number, lines, index = self.lt.trace_next(depth + 1)
257        lines = lines.strip()
258        if name is None:
259            return self.line_template_name_less.format(index=self.index, file_name=filename, line=line_number, func_name=function_name, code_line=lines)
260        else:
261            return self.line_template.format(index=self.index, name=name, file_name=filename, line=line_number, func_name=function_name, code_line=lines)
262
263    def print_next_line(self, name: Optional[str] = None, depth: int = 1):
264        if self.print_allowed:
265            print(self.next_line(name, depth + 1) + '\n')
266    
267    def __call__(self, depth: int = 1):
268        _, _, prev_line_number, prev_lines, _ = self.lt.trace(depth + 1)
269        filename, function_name, next_line_number, next_lines, _ = self.lt.trace_next(depth + 1)
270        return filename, function_name, prev_line_number, next_line_number, prev_lines, next_lines
AutoLineTracer( code_start_repl_type: CodeStartReplType = <CodeStartReplType.general: 0>, print_allowed: bool = True, rich_allowed: bool = True, *args, **kwargs)
 74    def __init__(self, code_start_repl_type: CodeStartReplType = CodeStartReplType.general, print_allowed: bool = True, rich_allowed: bool = True, *args, **kwargs):
 75        self.code_start_repl_type: CodeStartReplType = code_start_repl_type
 76        self.print_allowed: bool = print_allowed
 77        self.rich_allowed: bool = rich_allowed
 78        if CodeStartReplType.general == code_start_repl_type:
 79            self.code_start_repl = self._start_impl_general
 80        elif CodeStartReplType.general_verbose == code_start_repl_type:
 81            self.code_start_repl = self._start_impl_general_verbose
 82        elif CodeStartReplType.limited == code_start_repl_type:
 83            self.code_start_repl = self._start_impl_limited
 84        elif CodeStartReplType.limited_verbose == code_start_repl_type:
 85            self.code_start_repl = self._start_impl_limited_verbose
 86        
 87        self.lt: LineTracer = LineTracer(*args, **kwargs)
 88        self._index: IDGenerator = IDGenerator()
 89        self.line_template: str = '#{index:<4n}| <[{name}]> | <file \'{file_name}\' line {line}>.{func_name}()\n\t| {code_line}'
 90        self.line_template_name_less: str = '#{index:<4n}| <file \'{file_name}\' line {line}>.{func_name}()\n\t| {code_line}'
 91        # self.start_template: str = '#{index:<4n}| <+[{name}]+>'
 92        self.start_template: str = '#{index:<4n}| <+[{short_name}]+>\n\t|<+[{name}]+>'
 93        self.end_template: str = '#{index:<4n}| <-[{short_name}]->\n\t|<-[{name}]->'
 94
 95        self.s = self.start
 96        self.e = self.end
 97        self.p = self.previous_line
 98        self.c = self.current_line
 99        self.n = self.next_line
100
101        self.ps = self.print_start
102        self.pe = self.print_end
103        self.pp = self.print_previous_line
104        self.pc = self.print_current_line
105        self.pcptv = self.print_current_line_pp_type_value
106        self.pcpt = self.print_current_line_pp_value
107        self.pn = self.print_next_line
code_start_repl_type: CodeStartReplType
print_allowed: bool
rich_allowed: bool
lt: cengal.code_inspection.line_tracer.versions.v_0.line_tracer.LineTracer
line_template: str
line_template_name_less: str
start_template: str
end_template: str
s
e
p
c
n
ps
pe
pp
pc
pcptv
pcpt
pn
index
109    @property
110    def index(self):
111        return self._index()
def start(self, depth: int = 1):
125    def start(self, depth: int = 1):
126        short_name = self._start_impl_limited(depth + 1)
127        name = self.code_start_repl(depth + 1)
128        return self.start_template.format(index=self.index, short_name=short_name, name=name)
def print_start(self, depth: int = 1):
130    def print_start(self, depth: int = 1):
131        if self.print_allowed:
132            print(self.start(depth + 1) + '\n')
def end(self, depth: int = 1):
134    def end(self, depth: int = 1):
135        short_name = self._start_impl_limited(depth + 1)
136        name = self.code_start_repl(depth + 1)
137        return self.end_template.format(index=self.index, short_name=short_name, name=name)
def print_end(self, depth: int = 1):
139    def print_end(self, depth: int = 1):
140        if self.print_allowed:
141            print(self.end(depth + 1) + '\n')
def previous_line(self, name: Union[str, NoneType] = None, depth: int = 1):
143    def previous_line(self, name: Optional[str] = None, depth: int = 1):
144        filename, function_name, line_number, lines, index = self.lt.trace(depth + 1)
145        lines = lines.strip()
146        if name is None:
147            return self.line_template_name_less.format(index=self.index, file_name=filename, line=line_number, func_name=function_name, code_line=lines)
148        else:
149            return self.line_template.format(index=self.index, name=name, file_name=filename, line=line_number, func_name=function_name, code_line=lines)
def print_previous_line(self, name: Union[str, NoneType] = None, depth: int = 1):
151    def print_previous_line(self, name: Optional[str] = None, depth: int = 1):
152        if self.print_allowed:
153            print(self.previous_line(name, depth + 1) + '\n')
def current_line( self, line_result, name: Union[str, NoneType] = None, line_type: LineType = <LineType.current_line: 1>, line_num: Union[int, NoneType] = None, output_fields: Union[Set[OutputFields], NoneType] = None, depth: int = 1):
155    def current_line(self, line_result, name: Optional[str] = None, line_type: LineType = LineType.current_line, line_num: Optional[int] = None, 
156                     output_fields: Optional[Set[OutputFields]] = None, 
157                     depth: int = 1):
158        if output_fields is None:
159            output_fields = {
160                OutputFields.trace_name, 
161                OutputFields.file_name,
162                OutputFields.line,
163                OutputFields.func_name,
164                OutputFields.code_line,
165                OutputFields.result,
166            }
167
168        if LineType.current_line == line_type:
169            filename, function_name, line_number, lines, index = self.lt.trace_self(depth + 1)
170        elif LineType.exact_line == line_type:
171            filename, function_name, line_number, lines, index = self.lt.trace_exact(line_num, depth + 1)
172        elif LineType.relative_line == line_type:
173            filename, function_name, line_number, lines, index = self.lt.trace_relative(line_num, depth + 1)
174        elif LineType.previous_line == line_type:
175            filename, function_name, line_number, lines, index = self.lt.trace(depth + 1)
176        elif LineType.next_line == line_type:
177            filename, function_name, line_number, lines, index = self.lt.trace_next(depth + 1)
178
179        lines = lines.strip()
180        if name is None:
181            result = self.line_template_name_less.format(index=self.index, file_name=filename, line=line_number, func_name=function_name, code_line=lines)
182        else:
183            result = self.line_template.format(index=self.index, name=name, file_name=filename, line=line_number, func_name=function_name, code_line=lines)
184        
185        if OutputFields.result in output_fields:
186            result += f'\n\t\t| {line_result}'
187        
188        return result
def print_current_line( self, line_result, name: Union[str, NoneType] = None, line_type: LineType = <LineType.current_line: 1>, line_num: Union[int, NoneType] = None, output_fields: Union[Set[OutputFields], NoneType] = None, depth: int = 1) -> Any:
190    def print_current_line(self, line_result, name: Optional[str] = None, line_type: LineType = LineType.current_line, line_num: Optional[int] = None, output_fields: Optional[Set[OutputFields]] = None, depth: int = 1) -> Any:
191        if output_fields is None:
192            output_fields = {
193                OutputFields.trace_name, 
194                OutputFields.file_name,
195                OutputFields.line,
196                OutputFields.func_name,
197                OutputFields.code_line,
198                OutputFields.result,
199                OutputFields.new_line_after_end,
200            }
201
202        if self.print_allowed:
203            if RICH_PRESENT and self.rich_allowed:
204                from rich.console import Console
205                from rich.syntax import Syntax
206
207                if LineType.current_line == line_type:
208                    filename, function_name, line_number, lines, index = self.lt.trace_self(depth + 1)
209                elif LineType.exact_line == line_type:
210                    filename, function_name, line_number, lines, index = self.lt.trace_exact(line_num, depth + 1)
211                elif LineType.relative_line == line_type:
212                    filename, function_name, line_number, lines, index = self.lt.trace_relative(line_num, depth + 1)
213                elif LineType.previous_line == line_type:
214                    filename, function_name, line_number, lines, index = self.lt.trace(depth + 1)
215                elif LineType.next_line == line_type:
216                    filename, function_name, line_number, lines, index = self.lt.trace_next(depth + 1)
217
218                # lines = lines.strip()
219                syntax = Syntax(lines, "python", theme="monokai", line_numbers=True, start_line=line_number)
220                console = Console()
221                cl = self.current_line(line_result, name, line_type, line_num, output_fields, depth + 1)
222                clines = cl.split('\n')
223                # print(clines[0])
224                console.print(clines[0])
225                console.print(syntax)
226                clines_rest = clines[2:]
227                for cline in clines_rest:
228                    console.print(cline)
229                
230                if OutputFields.new_line_after_end in output_fields:
231                    print()
232                    # console.print(clines[3])
233                    # print(clines[2])
234            else:
235                if OutputFields.new_line_after_end in output_fields:
236                    ending = '\n'
237                else:
238                    ending = ''
239
240                print(self.current_line(line_result, name, line_type, line_num, output_fields, depth + 1) + ending)
241        
242        return line_result
def print_current_line_pp_type_value( self, line_result, name: Union[str, NoneType] = None, line_type: LineType = <LineType.current_line: 1>, line_num: Union[int, NoneType] = None, output_fields: Union[Set[OutputFields], NoneType] = None, depth: int = 1) -> Any:
244    def print_current_line_pp_type_value(self, line_result, name: Optional[str] = None, line_type: LineType = LineType.current_line, line_num: Optional[int] = None, output_fields: Optional[Set[OutputFields]] = None, depth: int = 1) -> Any:
245        multistr_data_value: str = get_multistr_of_data_value(line_result, 3).lstrip(' \t')
246        str_template = f'{type(line_result)}\n\t\t| {multistr_data_value}'
247        self.print_current_line(str_template, name, line_type, line_num, output_fields, depth + 1)
248        return line_result
def print_current_line_pp_value( self, line_result, name: Union[str, NoneType] = None, line_type: LineType = <LineType.current_line: 1>, line_num: Union[int, NoneType] = None, output_fields: Union[Set[OutputFields], NoneType] = None, depth: int = 1) -> Any:
250    def print_current_line_pp_value(self, line_result, name: Optional[str] = None, line_type: LineType = LineType.current_line, line_num: Optional[int] = None, output_fields: Optional[Set[OutputFields]] = None, depth: int = 1) -> Any:
251        str_template = get_multistr_of_data_value(line_result, 3).lstrip(' \t')
252        self.print_current_line(str_template, name, line_type, line_num, output_fields, depth + 1)
253        return line_result
def next_line(self, name: Union[str, NoneType] = None, depth: int = 1):
255    def next_line(self, name: Optional[str] = None, depth: int = 1):
256        filename, function_name, line_number, lines, index = self.lt.trace_next(depth + 1)
257        lines = lines.strip()
258        if name is None:
259            return self.line_template_name_less.format(index=self.index, file_name=filename, line=line_number, func_name=function_name, code_line=lines)
260        else:
261            return self.line_template.format(index=self.index, name=name, file_name=filename, line=line_number, func_name=function_name, code_line=lines)
def print_next_line(self, name: Union[str, NoneType] = None, depth: int = 1):
263    def print_next_line(self, name: Optional[str] = None, depth: int = 1):
264        if self.print_allowed:
265            print(self.next_line(name, depth + 1) + '\n')
auto_line_tracer__general = <AutoLineTracer object>
auto_line_tracer__general_verbose = <AutoLineTracer object>
auto_line_tracer__limited = <AutoLineTracer object>
auto_line_tracer__limited_verbose = <AutoLineTracer object>
altg = <AutoLineTracer object>
altgv = <AutoLineTracer object>
altl = <AutoLineTracer object>
altlv = <AutoLineTracer object>
alt = <AutoLineTracer object>
def trace_self__general( line_result, name: Union[str, NoneType] = None, line_type: LineType = <LineType.current_line: 1>, line_num: Union[int, NoneType] = None, output_fields: Union[Set[OutputFields], NoneType] = None, depth: int = 1) -> Any:
286def trace_self__general(line_result, name: Optional[str] = None, line_type: LineType = LineType.current_line, line_num: Optional[int] = None, output_fields: Optional[Set[OutputFields]] = None, depth: int = 1) -> Any:
287    return auto_line_tracer__general.print_current_line_pp_type_value(line_result, name, line_type, line_num, output_fields, depth + 1)
def trace_self__general_verbose( line_result, name: Union[str, NoneType] = None, line_type: LineType = <LineType.current_line: 1>, line_num: Union[int, NoneType] = None, output_fields: Union[Set[OutputFields], NoneType] = None, depth: int = 1) -> Any:
290def trace_self__general_verbose(line_result, name: Optional[str] = None, line_type: LineType = LineType.current_line, line_num: Optional[int] = None, output_fields: Optional[Set[OutputFields]] = None, depth: int = 1) -> Any:
291    return auto_line_tracer__general_verbose.print_current_line_pp_type_value(line_result, name, line_type, line_num, output_fields, depth + 1)
def trace_self__limited( line_result, name: Union[str, NoneType] = None, line_type: LineType = <LineType.current_line: 1>, line_num: Union[int, NoneType] = None, output_fields: Union[Set[OutputFields], NoneType] = None, depth: int = 1) -> Any:
294def trace_self__limited(line_result, name: Optional[str] = None, line_type: LineType = LineType.current_line, line_num: Optional[int] = None, output_fields: Optional[Set[OutputFields]] = None, depth: int = 1) -> Any:
295    return auto_line_tracer__limited.print_current_line_pp_type_value(line_result, name, line_type, line_num, output_fields, depth + 1)
def trace_self__limited_verbose( line_result, name: Union[str, NoneType] = None, line_type: LineType = <LineType.current_line: 1>, line_num: Union[int, NoneType] = None, output_fields: Union[Set[OutputFields], NoneType] = None, depth: int = 1) -> Any:
298def trace_self__limited_verbose(line_result, name: Optional[str] = None, line_type: LineType = LineType.current_line, line_num: Optional[int] = None, output_fields: Optional[Set[OutputFields]] = None, depth: int = 1) -> Any:
299    return auto_line_tracer__limited_verbose.print_current_line_pp_type_value(line_result, name, line_type, line_num, output_fields, depth + 1)
def tsg( line_result, name: Union[str, NoneType] = None, line_type: LineType = <LineType.current_line: 1>, line_num: Union[int, NoneType] = None, output_fields: Union[Set[OutputFields], NoneType] = None, depth: int = 1) -> Any:
286def trace_self__general(line_result, name: Optional[str] = None, line_type: LineType = LineType.current_line, line_num: Optional[int] = None, output_fields: Optional[Set[OutputFields]] = None, depth: int = 1) -> Any:
287    return auto_line_tracer__general.print_current_line_pp_type_value(line_result, name, line_type, line_num, output_fields, depth + 1)
def tsgv( line_result, name: Union[str, NoneType] = None, line_type: LineType = <LineType.current_line: 1>, line_num: Union[int, NoneType] = None, output_fields: Union[Set[OutputFields], NoneType] = None, depth: int = 1) -> Any:
290def trace_self__general_verbose(line_result, name: Optional[str] = None, line_type: LineType = LineType.current_line, line_num: Optional[int] = None, output_fields: Optional[Set[OutputFields]] = None, depth: int = 1) -> Any:
291    return auto_line_tracer__general_verbose.print_current_line_pp_type_value(line_result, name, line_type, line_num, output_fields, depth + 1)
def tsl( line_result, name: Union[str, NoneType] = None, line_type: LineType = <LineType.current_line: 1>, line_num: Union[int, NoneType] = None, output_fields: Union[Set[OutputFields], NoneType] = None, depth: int = 1) -> Any:
294def trace_self__limited(line_result, name: Optional[str] = None, line_type: LineType = LineType.current_line, line_num: Optional[int] = None, output_fields: Optional[Set[OutputFields]] = None, depth: int = 1) -> Any:
295    return auto_line_tracer__limited.print_current_line_pp_type_value(line_result, name, line_type, line_num, output_fields, depth + 1)
def tslv( line_result, name: Union[str, NoneType] = None, line_type: LineType = <LineType.current_line: 1>, line_num: Union[int, NoneType] = None, output_fields: Union[Set[OutputFields], NoneType] = None, depth: int = 1) -> Any:
298def trace_self__limited_verbose(line_result, name: Optional[str] = None, line_type: LineType = LineType.current_line, line_num: Optional[int] = None, output_fields: Optional[Set[OutputFields]] = None, depth: int = 1) -> Any:
299    return auto_line_tracer__limited_verbose.print_current_line_pp_type_value(line_result, name, line_type, line_num, output_fields, depth + 1)
def ts( line_result, name: Union[str, NoneType] = None, line_type: LineType = <LineType.current_line: 1>, line_num: Union[int, NoneType] = None, output_fields: Union[Set[OutputFields], NoneType] = None, depth: int = 1) -> Any:
286def trace_self__general(line_result, name: Optional[str] = None, line_type: LineType = LineType.current_line, line_num: Optional[int] = None, output_fields: Optional[Set[OutputFields]] = None, depth: int = 1) -> Any:
287    return auto_line_tracer__general.print_current_line_pp_type_value(line_result, name, line_type, line_num, output_fields, depth + 1)
def fake_trace_self( line_result, name: Union[str, NoneType] = None, line_type: LineType = <LineType.current_line: 1>, line_num: Union[int, NoneType] = None, output_fields: Union[Set[OutputFields], NoneType] = None, depth: int = 1):
310def fake_trace_self(line_result, name: Optional[str] = None, line_type: LineType = LineType.current_line, line_num: Optional[int] = None, output_fields: Optional[Set[OutputFields]] = None, depth: int = 1):
311    return line_result
def fts( line_result, name: Union[str, NoneType] = None, line_type: LineType = <LineType.current_line: 1>, line_num: Union[int, NoneType] = None, output_fields: Union[Set[OutputFields], NoneType] = None, depth: int = 1):
310def fake_trace_self(line_result, name: Optional[str] = None, line_type: LineType = LineType.current_line, line_num: Optional[int] = None, output_fields: Optional[Set[OutputFields]] = None, depth: int = 1):
311    return line_result