# Path: snoop/utils.py
# PY34 = sys.version_info[:2] == (3, 4)
# NO_ASTTOKENS = PY34
# PYPY = 'pypy' in sys.version.lower()
# NO_BIRDSEYE = NO_ASTTOKENS or PYPY
# REPR_TARGET_LENGTH = 100
# def shitcode(s):
# def truncate(seq, max_length, middle):
# def truncate_string(string, max_length):
# def truncate_list(lst, max_length):
# def ensure_tuple(x, split=False):
# def short_filename(code):
# def is_comprehension_frame(frame):
# def needs_parentheses(source):
#     def code(s):
# def with_needed_parentheses(source):
# def my_cheap_repr(x):
#     def __init__(self, factory):
#     def __missing__(self, key):
# def optional_numeric_label(i, lst):
# def is_pathlike(x):
#     def iscoroutinefunction(_):
# def no_args_decorator(args, kwargs):
#     def __repr__(self):
# def _register_cheap_reprs():
#     def _sample_indices(length, max_length):
#     def _repr_series_one_line(x, helper):
# class ArgDefaultDict(dict):
#     class FormattedValue(object):
# class DirectRepr(str):
#     class QuerySet(object):


import ast
import opcode
import threading
import traceback
import executing
import six
from collections import defaultdict
from datetime import datetime
from textwrap import dedent
from pygments import highlight
from pygments.formatters.terminal256 import Terminal256Formatter
from pygments.lexers.python import Python3Lexer
from pygments.styles.monokai import MonokaiStyle
from six import PY3
from snoop.utils import ensure_tuple, short_filename, my_cheap_repr, \
    NO_ASTTOKENS, optional_numeric_label, try_statement, FormattedValue, ArgDefaultDict, lru_cache
    from pygments.lexers.python import Python2Lexer
    from pygments.lexers.python import PythonLexer as Python2Lexer
lexer = (Python3Lexer if PY3 else Python2Lexer)(stripnl=False)


class ForceWhiteTerminal256Formatter(Terminal256Formatter):
    def _closest_color(self, r, g, b):
        result = super(ForceWhiteTerminal256Formatter, self)._closest_color(r, g, b)
        if result == 15:
            result += 6 ** 3
        return result


class NeutralMonokaiStyle(MonokaiStyle):
    """
    Monokai style that is somewhat readable on both dark and light backgrounds
    by replacing 'white' styles with no style so that the terminal can automatically
    use the appropriate foreground color.
    """
    styles = {
        k: '' if v == '#f8f8f2' else v
        for k, v in MonokaiStyle.styles.items()
    }


formatters = ArgDefaultDict(lambda style: ForceWhiteTerminal256Formatter(style=style))


def raw_highlight(code, style):
    return highlight(code, lexer, formatters[style])



# Path: snoop/utils.py
# PY34 = sys.version_info[:2] == (3, 4)
# NO_ASTTOKENS = PY34
# PYPY = 'pypy' in sys.version.lower()
# NO_BIRDSEYE = NO_ASTTOKENS or PYPY
# REPR_TARGET_LENGTH = 100
# def shitcode(s):
# def truncate(seq, max_length, middle):
# def truncate_string(string, max_length):
# def truncate_list(lst, max_length):
# def ensure_tuple(x, split=False):
# def short_filename(code):
# def is_comprehension_frame(frame):
# def needs_parentheses(source):
#     def code(s):
# def with_needed_parentheses(source):
# def my_cheap_repr(x):
#     def __init__(self, factory):
#     def __missing__(self, key):
# def optional_numeric_label(i, lst):
# def is_pathlike(x):
#     def iscoroutinefunction(_):
# def no_args_decorator(args, kwargs):
#     def __repr__(self):
# def _register_cheap_reprs():
#     def _sample_indices(length, max_length):
#     def _repr_series_one_line(x, helper):
# class ArgDefaultDict(dict):
#     class FormattedValue(object):
# class DirectRepr(str):
#     class QuerySet(object):


# Path: snoop/formatting.py
import ast
import opcode
import threading
import traceback
import executing
import six
from collections import defaultdict
from datetime import datetime
from textwrap import dedent
from pygments import highlight
from pygments.formatters.terminal256 import Terminal256Formatter
from pygments.lexers.python import Python3Lexer
from pygments.styles.monokai import MonokaiStyle
from six import PY3
from snoop.utils import ensure_tuple, short_filename, my_cheap_repr, \
    NO_ASTTOKENS, optional_numeric_label, try_statement, FormattedValue, ArgDefaultDict, lru_cache
    from pygments.lexers.python import Python2Lexer
    from pygments.lexers.python import PythonLexer as Python2Lexer

lexer = (Python3Lexer if PY3 else Python2Lexer)(stripnl=False)


class ForceWhiteTerminal256Formatter(Terminal256Formatter):
    def _closest_color(self, r, g, b):
        result = super(ForceWhiteTerminal256Formatter, self)._closest_color(r, g, b)
        if result == 15:
            result += 6 ** 3
        return result


class NeutralMonokaiStyle(MonokaiStyle):
    """
    Monokai style that is somewhat readable on both dark and light backgrounds
    by replacing 'white' styles with no style so that the terminal can automatically
    use the appropriate foreground color.
    """
    styles = {
        k: '' if v == '#f8f8f2' else v
        for k, v in MonokaiStyle.styles.items()
    }


formatters = ArgDefaultDict(lambda style: ForceWhiteTerminal256Formatter(style=style))


def raw_highlight(code, style):
    return highlight(code, lexer, formatters[style])



cached_highlight = lru_cache(maxsize=1024)(raw_highlight)