<commit_before>
# Copyright 2017-present Open Networking Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


import base64
import datetime
import inspect
import pytz
import threading
import time
from protos import xos_pb2
from google.protobuf.empty_pb2 import Empty
import grpc
import json

from django.contrib.contenttypes.models import ContentType
from django.contrib.auth import authenticate as django_authenticate
from django.db.models import F, Q
from core.models import *
from xos.exceptions import *

from importlib import import_module
from django.conf import settings

from xosconfig import Config
from multistructlog import create_logger
log = create_logger(Config().get('logging'))


class XOSDefaultSecurityContext(object):
    grant_access = True
    write_access = True
    read_access = True


xos_anonymous_site = Site(
    name='XOS Anonymous Site',
    enabled=True,
    hosts_nodes=False,
    hosts_users=True,
    login_base='xos',
    abbreviated_name='xos-anonymous')

xos_anonymous_user = User(
    username='XOS Anonymous User',
    email='<EMAIL>',
    is_admin=False,
    site=xos_anonymous_site)

SessionStore = import_module(settings.SESSION_ENGINE).SessionStore


def translate_exceptions(function):
    """ this decorator translates XOS exceptions to grpc status codes """
    def wrapper(*args, **kwargs):
        try:
            return function(*args, **kwargs)
        except Exception as e:<commit_msg>[CORD-2696] Printing stacktrace for gRPC errors<commit_after>
# Copyright 2017-present Open Networking Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


import base64
import datetime
import inspect
import pytz
import threading
import time
from protos import xos_pb2
from google.protobuf.empty_pb2 import Empty
import grpc
import json

from django.contrib.contenttypes.models import ContentType
from django.contrib.auth import authenticate as django_authenticate
from django.db.models import F, Q
from core.models import *
from xos.exceptions import *

from importlib import import_module
from django.conf import settings

from xosconfig import Config
from multistructlog import create_logger
log = create_logger(Config().get('logging'))


class XOSDefaultSecurityContext(object):
    grant_access = True
    write_access = True
    read_access = True


xos_anonymous_site = Site(
    name='XOS Anonymous Site',
    enabled=True,
    hosts_nodes=False,
    hosts_users=True,
    login_base='xos',
    abbreviated_name='xos-anonymous')

xos_anonymous_user = User(
    username='XOS Anonymous User',
    email='<EMAIL>',
    is_admin=False,
    site=xos_anonymous_site)

SessionStore = import_module(settings.SESSION_ENGINE).SessionStore


def translate_exceptions(function):
    """ this decorator translates XOS exceptions to grpc status codes """
    def wrapper(*args, **kwargs):
        try:
            return function(*args, **kwargs)
        except Exception as e:

            import traceback
            tb = traceback.format_exc()
            print tb
            # TODO can we propagate it over the APIs?
{'fraction_non_alphanumeric': 0.07021433850702144, 'fraction_numerical': 0.006898250800689825, 'mean_word_length': 4.252263906856403, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2850681', 'n_tokens_mistral': 1138, 'n_tokens_neox': 1097, 'n_words': 412}