HEX
Server: Apache/2.4.46 (Win64) OpenSSL/1.1.1j PHP/8.4.25
System: Windows NT DESKTOP-4TAV2RJ 10.0 build 19045 (Windows 10) AMD64
User: fred (0)
PHP: 8.4.25
Disabled: NONE
Upload Files
File: C:/Users/fred/anaconda3/Lib/site-packages/fastjsonschema/indent.py
def indent(func):
    """
    Decorator for allowing to use method as normal method or with
    context manager for auto-indenting code blocks.
    """
    def wrapper(self, line, *args, optimize=True, **kwds):
        last_line = self._indent_last_line
        line = func(self, line, *args, **kwds)
        # When two blocks have the same condition (such as value has to be dict),
        # do the check only once and keep it under one block.
        if optimize and last_line == line:
            self._code.pop()
        self._indent_last_line = line
        return Indent(self, line)
    return wrapper


class Indent:
    def __init__(self, instance, line):
        self.instance = instance
        self.line = line

    def __enter__(self):
        self.instance._indent += 1

    def __exit__(self, type_, value, traceback):
        self.instance._indent -= 1
        self.instance._indent_last_line = self.line