<commit_before>"""
Debugging utilities for constructs
"""

import sys
import traceback
import pdb
import inspect

from construct import *
from construct.lib import *


class Probe(Construct):
    r"""
    A probe: dumps the context, stack frames, and stream content to the screen to aid the debugging process.

    :param name: the display name
    :param show_stream: whether or not to show stream contents. default is True. the stream must be seekable.
    :param show_context: whether or not to show the context. default is True.
    :param show_stack: whether or not to show the upper stack frames. default is True.
    :param stream_lookahead: the number of bytes to dump when show_stack is set. default is 100.
    
    Example::
        >>> (Byte >> Probe() >> Byte).build([1,2])

        ================================================================================
        Probe <unnamed 2>
        Container: 
            stream_position = 1
            following_stream_data = EOF reached
            context = Container: 
            stack = ListContainer: 
                Container: 
                    obj = [1, 2]
                    context = None
                    stream = <_io.BytesIO object at 0x7f32d5fce990>
                    self = <Sequence: None>
                    kw = {}
                Container: 
                    obj = [1, 2]
                    context = Container: 
                    stream = <_io.BytesIO object at 0x7f32d5fce990>
                    self = <Sequence: None>
                    kw = {}
                Container: 
                    obj = [1, 2]
                    context = Container: 
                    subobj = 2
                    i = 1
                    buildret = None
                    sc = Probe('<unnamed 2>')
                    stream = <_io.BytesIO object at 0x7f32d5fce990>
                    objiter = <list_iterator object at 0x7f32da018400>
                    self = <Sequence: None>
                Container: 
                    obj = 2
                    context = Container: 
                    stream = <_io.BytesIO object at 0x7f32d5fce990>
                    self = Probe('<unnamed 2>')
        ================================================================================
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
          File "/home/arkadiusz/Dokumenty/GitHub/construct/construct/core.py", line 218, in build
            self.build_stream(obj, stream, context, **kw)
          File "/home/arkadiusz/Dokumenty/GitHub/construct/construct/core.py", line 230, in build_stream
            self._build(obj, stream, context)
          File "/home/arkadiusz/Dokumenty/GitHub/construct/construct/core.py", line 925, in _build
            subobj = next(objiter)
        StopIteration
    """
    __slots__ = ["printname", "show_stream", "show_context", "show_stack", "stream_lookahead"]
    counter = 0
    
    def __init__(self, name=None, show_stream=True, show_context=True, show_stack=True, stream_lookahead=128):
        super(Probe, self).__init__()
        if name is None:<commit_msg>Debug docstrigns fixed<commit_after>"""
Debugging utilities for constructs
"""

import sys
import traceback
import pdb
import inspect

from construct import *
from construct.lib import *


class Probe(Construct):
    r"""
    A probe: dumps the context, stack frames, and stream content to the screen to aid the debugging process.

    :param name: the display name
    :param show_stream: whether or not to show stream contents. default is True. the stream must be seekable.
    :param show_context: whether or not to show the context. default is True.
    :param show_stack: whether or not to show the upper stack frames. default is True.
    :param stream_lookahead: the number of bytes to dump when show_stack is set. default is 100.
    
    Example::
        >>>> Struct("count"/Byte, "items"/Byte[this.count], Probe()).parse(b"\x05abcde")
        ================================================================================
        Probe <unnamed 3>
        EOF reached
        Container: 
            count = 5
            items = ListContainer: 
                97
                98
                99
                100
                101
        ================================================================================
        Container(count=5)(items=[97, 98, 99, 100, 101])

        >>>> (Byte >> Probe()).parse(b"?")
        ================================================================================
        Probe <unnamed 1>
        EOF reached
        Container: 
            0 = 63
        ================================================================================
        [63, None]
    """
    __slots__ = ["printname", "show_stream", "show_context", "show_stack", "stream_lookahead"]
    counter = 0
    
    def __init__(self, name=None, show_stream=True, show_context=True, show_stack=True, stream_lookahead=128):
        super(Probe, self).__init__()
        if name is None:
{'fraction_non_alphanumeric': 0.17390446111330438, 'fraction_numerical': 0.02289774970390841, 'mean_word_length': 2.0990825688073396, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3991982', 'n_tokens_mistral': 1416, 'n_tokens_neox': 1240, 'n_words': 412}