# Path: radon/cli/colors.py
# def color_enabled():
#     COLOR_ENV = os.getenv('COLOR', 'auto')
#     GREEN, YELLOW, RED = (
#         colorama.Fore.GREEN,
#         colorama.Fore.YELLOW,
#         colorama.Fore.RED,
#     )
#     MAGENTA, CYAN, WHITE = (
#         colorama.Fore.MAGENTA,
#         colorama.Fore.CYAN,
#         colorama.Fore.WHITE,
#     )
#     BRIGHT, RESET = colorama.Style.BRIGHT, colorama.Style.RESET_ALL
#     GREEN = YELLOW = RED = MAGENTA = CYAN = WHITE = BRIGHT = RESET = ''
# RANKS_COLORS = {
#     'A': GREEN,
#     'B': GREEN,
#     'C': YELLOW,
#     'D': YELLOW,
#     'E': RED,
#     'F': RED,
# }
# LETTERS_COLORS = {'F': MAGENTA, 'C': CYAN, 'M': WHITE}
# MI_RANKS = {'A': GREEN, 'B': YELLOW, 'C': RED}
# TEMPLATE = '{0}{1} {reset}{2}:{3} {4} - {5}{6}{reset}'
# 
# Path: radon/complexity.py
# def cc_rank(cc):
#     r'''Rank the complexity score from A to F, where A stands for the simplest
#     and best score and F the most complex and worst one:
# 
#     ============= =====================================================
#         1 - 5        A (low risk - simple block)
#         6 - 10       B (low risk - well structured and stable block)
#         11 - 20      C (moderate risk - slightly complex block)
#         21 - 30      D (more than moderate risk - more complex block)
#         31 - 40      E (high risk - complex block, alarming)
#         41+          F (very high risk - error-prone, unstable block)
#     ============= =====================================================
# 
#     Here *block* is used in place of function, method or class.
# 
#     The formula used to convert the score into an index is the following:
# 
#     .. math::
# 
#         \text{rank} = \left \lceil \dfrac{\text{score}}{10} \right \rceil
#         - H(5 - \text{score})
# 
#     where ``H(s)`` stands for the Heaviside Step Function.
#     The rank is then associated to a letter (0 = A, 5 = F).
#     '''
#     if cc < 0:
#         raise ValueError('Complexity must be a non-negative value')
#     return chr(
#         min(int(math.ceil(cc / 10.0) or 1) - (1, 0)[5 - cc < 0], 5) + 65
#     )
# 
# Path: radon/visitors.py
# class Function(BaseFunc):
#     '''Object represeting a function block.'''
# 
#     @property
#     def letter(self):
#         '''The letter representing the function. It is `M` if the function is
#         actually a method, `F` otherwise.
#         '''
#         return 'M' if self.is_method else 'F'
# 
#     @property
#     def fullname(self):
#         '''The full name of the function. If it is a method, then the full name
#         is:
#                 {class name}.{method name}
#         Otherwise it is just the function name.
#         '''
#         if self.classname is None:
#             return self.name
#         return '{0}.{1}'.format(self.classname, self.name)
# 
#     def __str__(self):
#         '''String representation of a function block.'''
#         return '{0} {1}:{2}->{3} {4} - {5}'.format(
#             self.letter,
#             self.lineno,
#             self.col_offset,
#             self.endline,
#             self.fullname,
#             self.complexity,
#         )


import fnmatch
import hashlib
import json
import locale
import os
import platform
import re
import sys
import xml.etree.cElementTree as et
    import nbformat
from contextlib import contextmanager
from radon.cli.colors import (BRIGHT, LETTERS_COLORS, RANKS_COLORS, RESET,
                              TEMPLATE)
from radon.complexity import cc_rank
from radon.visitors import Function
        from codecs import open as _open_function
        from codecs import BOM_UTF8, lookup
        from io import TextIOWrapper
        from io import open as _io_open_function
        dirs[:] = list(filter_out(dirs, ignore))
        fullpaths = (os.path.normpath(os.path.join(root, p)) for p in files)
        for filename in filter_out(fullpaths, exclude):
            if not os.path.basename(filename).startswith(
                '.'
            ) and _is_python_file(filename):
                yield filename


def filter_out(strings, patterns):
    '''Filter out any string that matches any of the specified patterns.'''
    for s in strings:
        if all(not fnmatch.fnmatch(s, p) for p in patterns):
            yield s


def cc_to_dict(obj):
    '''Convert an object holding CC results into a dictionary. This is meant
    for JSON dumping.'''

    def get_type(obj):
        '''The object can be of type *method*, *function* or *class*.'''
        if isinstance(obj, Function):
            return 'method' if obj.is_method else 'function'
        return 'class'

    result = {
        'type': get_type(obj),
        'rank': cc_rank(obj.complexity),
    }

# Path: radon/cli/colors.py
# def color_enabled():
#     COLOR_ENV = os.getenv('COLOR', 'auto')
#     GREEN, YELLOW, RED = (
#         colorama.Fore.GREEN,
#         colorama.Fore.YELLOW,
#         colorama.Fore.RED,
#     )
#     MAGENTA, CYAN, WHITE = (
#         colorama.Fore.MAGENTA,
#         colorama.Fore.CYAN,
#         colorama.Fore.WHITE,
#     )
#     BRIGHT, RESET = colorama.Style.BRIGHT, colorama.Style.RESET_ALL
#     GREEN = YELLOW = RED = MAGENTA = CYAN = WHITE = BRIGHT = RESET = ''
# RANKS_COLORS = {
#     'A': GREEN,
#     'B': GREEN,
#     'C': YELLOW,
#     'D': YELLOW,
#     'E': RED,
#     'F': RED,
# }
# LETTERS_COLORS = {'F': MAGENTA, 'C': CYAN, 'M': WHITE}
# MI_RANKS = {'A': GREEN, 'B': YELLOW, 'C': RED}
# TEMPLATE = '{0}{1} {reset}{2}:{3} {4} - {5}{6}{reset}'
# 
# Path: radon/complexity.py
# def cc_rank(cc):
#     r'''Rank the complexity score from A to F, where A stands for the simplest
#     and best score and F the most complex and worst one:
# 
#     ============= =====================================================
#         1 - 5        A (low risk - simple block)
#         6 - 10       B (low risk - well structured and stable block)
#         11 - 20      C (moderate risk - slightly complex block)
#         21 - 30      D (more than moderate risk - more complex block)
#         31 - 40      E (high risk - complex block, alarming)
#         41+          F (very high risk - error-prone, unstable block)
#     ============= =====================================================
# 
#     Here *block* is used in place of function, method or class.
# 
#     The formula used to convert the score into an index is the following:
# 
#     .. math::
# 
#         \text{rank} = \left \lceil \dfrac{\text{score}}{10} \right \rceil
#         - H(5 - \text{score})
# 
#     where ``H(s)`` stands for the Heaviside Step Function.
#     The rank is then associated to a letter (0 = A, 5 = F).
#     '''
#     if cc < 0:
#         raise ValueError('Complexity must be a non-negative value')
#     return chr(
#         min(int(math.ceil(cc / 10.0) or 1) - (1, 0)[5 - cc < 0], 5) + 65
#     )
# 
# Path: radon/visitors.py
# class Function(BaseFunc):
#     '''Object represeting a function block.'''
# 
#     @property
#     def letter(self):
#         '''The letter representing the function. It is `M` if the function is
#         actually a method, `F` otherwise.
#         '''
#         return 'M' if self.is_method else 'F'
# 
#     @property
#     def fullname(self):
#         '''The full name of the function. If it is a method, then the full name
#         is:
#                 {class name}.{method name}
#         Otherwise it is just the function name.
#         '''
#         if self.classname is None:
#             return self.name
#         return '{0}.{1}'.format(self.classname, self.name)
# 
#     def __str__(self):
#         '''String representation of a function block.'''
#         return '{0} {1}:{2}->{3} {4} - {5}'.format(
#             self.letter,
#             self.lineno,
#             self.col_offset,
#             self.endline,
#             self.fullname,
#             self.complexity,
#         )


# Path: radon/cli/tools.py
import fnmatch
import hashlib
import json
import locale
import os
import platform
import re
import sys
import xml.etree.cElementTree as et
    import nbformat
from contextlib import contextmanager
from radon.cli.colors import (BRIGHT, LETTERS_COLORS, RANKS_COLORS, RESET,
                              TEMPLATE)
from radon.complexity import cc_rank
from radon.visitors import Function
        from codecs import open as _open_function
        from codecs import BOM_UTF8, lookup
        from io import TextIOWrapper
        from io import open as _io_open_function

        dirs[:] = list(filter_out(dirs, ignore))
        fullpaths = (os.path.normpath(os.path.join(root, p)) for p in files)
        for filename in filter_out(fullpaths, exclude):
            if not os.path.basename(filename).startswith(
                '.'
            ) and _is_python_file(filename):
                yield filename


def filter_out(strings, patterns):
    '''Filter out any string that matches any of the specified patterns.'''
    for s in strings:
        if all(not fnmatch.fnmatch(s, p) for p in patterns):
            yield s


def cc_to_dict(obj):
    '''Convert an object holding CC results into a dictionary. This is meant
    for JSON dumping.'''

    def get_type(obj):
        '''The object can be of type *method*, *function* or *class*.'''
        if isinstance(obj, Function):
            return 'method' if obj.is_method else 'function'
        return 'class'

    result = {
        'type': get_type(obj),
        'rank': cc_rank(obj.complexity),
    }

    attrs = set(Function._fields) - set(('is_method', 'closures'))