<commit_before>#coding: cp1251

import re, os, os.path, sys, datetime, types, linecache, warnings

from itertools import count as _count
from inspect import isfunction, ismethod
from time import strptime
from os import urandom
from codecs import BOM_UTF8, BOM_LE, BOM_BE
from locale import getpreferredencoding
from bisect import bisect
from copy import deepcopy, _deepcopy_dispatch

# deepcopy instance method patch for Python < 2.7:
if types.MethodType not in _deepcopy_dispatch:
    def _deepcopy_method(x, memo):
        return type(x)(x.im_func, deepcopy(x.im_self, memo), x.im_class)
    _deepcopy_dispatch[types.MethodType] = _deepcopy_method

import pony
from pony import options

try: from pony.thirdparty import etree
except ImportError: etree = None

if pony.MODE.startswith('GAE-'): localbase = object
else: from threading import local as localbase

class PonyDeprecationWarning(DeprecationWarning):
    pass

def deprecated(stacklevel, message):
    warnings.warn(message, PonyDeprecationWarning, stacklevel)

warnings.simplefilter('once', PonyDeprecationWarning)

def copy_func_attrs(new_func, old_func, decorator_name=None):
    if new_func is not old_func:
        if not isfunction(old_func) and not ismethod(old_func):
            throw(TypeError, 'Decorated object must be function or method. Got: %r' % old_func)
        new_func.__name__ = old_func.__name__
        new_func.__doc__ = old_func.__doc__
        new_func.__module__ = old_func.__module__
        d = old_func.__dict__.copy()
        d.update(new_func.__dict__)
        new_func.__dict__.update(d)
        if not hasattr(old_func, 'original_func'):
            new_func.original_func = old_func
    if not hasattr(new_func, 'decorators'):
        new_func.decorators = getattr(old_func, 'decorators', set()).copy()
    if decorator_name: new_func.decorators.add(decorator_name)
    return new_func

def simple_decorator(old_dec):
    def new_dec(old_func):
        def pony_wrapper(*args, **kwargs):
            return old_dec(old_func, *args, **kwargs)
        return copy_func_attrs(pony_wrapper, old_func, old_dec.__name__)
    return copy_func_attrs(new_dec, old_dec, 'simple_decorator')

@simple_decorator
def decorator(old_dec, old_func):
    new_func = old_dec(old_func)
    return copy_func_attrs(new_func, old_func, old_dec.__name__)

@simple_decorator
def decorator_with_params(old_dec, *args, **kwargs):
    if len(args) == 1 and not kwargs:
        old_func = args[0]
        new_func = old_dec(old_func)
        return copy_func_attrs(new_func, old_func, old_dec.__name__)
    def parameterized_decorator(old_func):
        new_func = old_dec(old_func, *args, **kwargs)
        return copy_func_attrs(new_func, old_func, old_dec.__name__)
    return parameterized_decorator

@decorator
def cut_traceback(old_func):
    def new_func(*args, **kwargs):
        if not (pony.MODE == 'INTERACTIVE' and options.CUT_TRACEBACK):
            return old_func(*args, **kwargs)
        try:
            return old_func(*args, **kwargs)
        except Exception:
            exc_type, exc, tb = sys.exc_info()
            last_pony_tb = None
            try:
                while tb.tb_next:
                    module_name = tb.tb_frame.f_globals['__name__']
                    if module_name == 'pony' or (module_name is not None  # may be None during import
                                                 and module_name.startswith('pony.')):
                        last_pony_tb = tb
                    tb = tb.tb_next
                if last_pony_tb is None: raise
                if tb.tb_frame.f_globals['__name__'] == 'pony.utils' and tb.tb_frame.f_code.co_name == 'throw':
                    raise exc_type, exc, last_pony_tb
                raise exc  # Set "pony.options.CUT_TRACEBACK = False" to see full traceback
            finally:
                del tb, last_pony_tb
    return new_func

def throw(exc_type, *args, **kwargs):
    if isinstance(exc_type, Exception):
        assert not args and not kwargs
        exc = exc_type
    else: exc = exc_type(*args, **kwargs)
    if not (pony.MODE == 'INTERACTIVE' and options.CUT_TRACEBACK):
        raise exc
    else:
        raise exc  # Set "pony.options.CUT_TRACEBACK = False" to see full traceback

_cache = {}<commit_msg>Bug fixed: frame does not necessarily have '__name__' in f_globals<commit_after>#coding: cp1251

import re, os, os.path, sys, datetime, types, linecache, warnings

from itertools import count as _count
from inspect import isfunction, ismethod
from time import strptime
from os import urandom
from codecs import BOM_UTF8, BOM_LE, BOM_BE
from locale import getpreferredencoding
from bisect import bisect
from copy import deepcopy, _deepcopy_dispatch

# deepcopy instance method patch for Python < 2.7:
if types.MethodType not in _deepcopy_dispatch:
    def _deepcopy_method(x, memo):
        return type(x)(x.im_func, deepcopy(x.im_self, memo), x.im_class)
    _deepcopy_dispatch[types.MethodType] = _deepcopy_method

import pony
from pony import options

try: from pony.thirdparty import etree
except ImportError: etree = None

if pony.MODE.startswith('GAE-'): localbase = object
else: from threading import local as localbase

class PonyDeprecationWarning(DeprecationWarning):
    pass

def deprecated(stacklevel, message):
    warnings.warn(message, PonyDeprecationWarning, stacklevel)

warnings.simplefilter('once', PonyDeprecationWarning)

def copy_func_attrs(new_func, old_func, decorator_name=None):
    if new_func is not old_func:
        if not isfunction(old_func) and not ismethod(old_func):
            throw(TypeError, 'Decorated object must be function or method. Got: %r' % old_func)
        new_func.__name__ = old_func.__name__
        new_func.__doc__ = old_func.__doc__
        new_func.__module__ = old_func.__module__
        d = old_func.__dict__.copy()
        d.update(new_func.__dict__)
        new_func.__dict__.update(d)
        if not hasattr(old_func, 'original_func'):
            new_func.original_func = old_func
    if not hasattr(new_func, 'decorators'):
        new_func.decorators = getattr(old_func, 'decorators', set()).copy()
    if decorator_name: new_func.decorators.add(decorator_name)
    return new_func

def simple_decorator(old_dec):
    def new_dec(old_func):
        def pony_wrapper(*args, **kwargs):
            return old_dec(old_func, *args, **kwargs)
        return copy_func_attrs(pony_wrapper, old_func, old_dec.__name__)
    return copy_func_attrs(new_dec, old_dec, 'simple_decorator')

@simple_decorator
def decorator(old_dec, old_func):
    new_func = old_dec(old_func)
    return copy_func_attrs(new_func, old_func, old_dec.__name__)

@simple_decorator
def decorator_with_params(old_dec, *args, **kwargs):
    if len(args) == 1 and not kwargs:
        old_func = args[0]
        new_func = old_dec(old_func)
        return copy_func_attrs(new_func, old_func, old_dec.__name__)
    def parameterized_decorator(old_func):
        new_func = old_dec(old_func, *args, **kwargs)
        return copy_func_attrs(new_func, old_func, old_dec.__name__)
    return parameterized_decorator

@decorator
def cut_traceback(old_func):
    def new_func(*args, **kwargs):
        if not (pony.MODE == 'INTERACTIVE' and options.CUT_TRACEBACK):
            return old_func(*args, **kwargs)
        try:
            return old_func(*args, **kwargs)
        except Exception:
            exc_type, exc, tb = sys.exc_info()
            last_pony_tb = None
            try:
                while tb.tb_next:
                    module_name = tb.tb_frame.f_globals['__name__']
                    if module_name == 'pony' or (module_name is not None  # may be None during import
                                                 and module_name.startswith('pony.')):
                        last_pony_tb = tb
                    tb = tb.tb_next
                if last_pony_tb is None: raise
                if tb.tb_frame.f_globals.get('__name__') == 'pony.utils' and tb.tb_frame.f_code.co_name == 'throw':
                    raise exc_type, exc, last_pony_tb
                raise exc  # Set "pony.options.CUT_TRACEBACK = False" to see full traceback
            finally:
                del tb, last_pony_tb
    return new_func

def throw(exc_type, *args, **kwargs):
    if isinstance(exc_type, Exception):
        assert not args and not kwargs
        exc = exc_type
    else: exc = exc_type(*args, **kwargs)
    if not (pony.MODE == 'INTERACTIVE' and options.CUT_TRACEBACK):
        raise exc
    else:
        raise exc  # Set "pony.options.CUT_TRACEBACK = False" to see full traceback

_cache = {}
{'fraction_non_alphanumeric': 0.0870170553428472, 'fraction_numerical': 0.002088409328228333, 'mean_word_length': 3.011167985109353, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1819588', 'n_tokens_mistral': 2733, 'n_tokens_neox': 2703, 'n_words': 693}