<commit_before>import base64
import datetime
import jsonschema
import os
import pymongo
import requests
import traceback
import webapp2

from .. import util
from .. import files
from .. import config
from ..types import Origin
from .. import validators
from ..auth.authproviders import AuthProvider, APIKeyAuthProvider
from ..auth import APIAuthProviderException, APIUnknownUserException, APIRefreshTokenException
from ..dao import APIConsistencyException, APIConflictException, APINotFoundException, APIPermissionException, APIValidationException
from ..dao.hierarchy import get_parent_tree
from ..web.request import log_access, AccessType


class RequestHandler(webapp2.RequestHandler):

    json_schema = None

    def __init__(self, request=None, response=None): # pylint: disable=super-init-not-called
        """Set uid, source_site, public_request, and superuser"""
        self.initialize(request, response)

        site_id = config.get_item('site', 'id')
        if site_id is None:
            self.abort(503, 'Database not initialized')

        self.source_site = None
        self.uid = None
        self.origin = None

        # If user is attempting to log in through `/login`, ignore Auth here:
        # In future updates, move login and logout handlers to class that overrides this init
        if self.request.path == '/api/login':
            self.source_site = site_id
            return

        try:
            # TODO: This should be taken out of base.RequestHandler so `handle_exception()`
            # can properly catch exceptions raised by this logic as well as uninteded exceptions
            # For now, wrap in a try/catch to prevent stack traces from getting to the client
            # For more info see scitran/core #733

            self.initialization_auth(site_id)

        except webapp2.HTTPException:
            raise
        except Exception: # pylint: disable=broad-except
            tb = traceback.format_exc()
            self.request.logger.error(tb)
            self.abort(500, 'Unexpected error.')



    def initialize(self, request, response):
        super(RequestHandler, self).initialize(request, response)
        request.logger.info("Initialized request")<commit_msg>use handle_exception in base.RequestHandler.__init__ (remove 500: Unexpected error.)<commit_after>import base64
import datetime
import jsonschema
import os
import pymongo
import requests
import traceback
import webapp2

from .. import util
from .. import files
from .. import config
from ..types import Origin
from .. import validators
from ..auth.authproviders import AuthProvider, APIKeyAuthProvider
from ..auth import APIAuthProviderException, APIUnknownUserException, APIRefreshTokenException
from ..dao import APIConsistencyException, APIConflictException, APINotFoundException, APIPermissionException, APIValidationException
from ..dao.hierarchy import get_parent_tree
from ..web.request import log_access, AccessType


class RequestHandler(webapp2.RequestHandler):

    json_schema = None

    def __init__(self, request=None, response=None): # pylint: disable=super-init-not-called
        """Set uid, source_site, public_request, and superuser"""
        self.initialize(request, response)

        site_id = config.get_item('site', 'id')
        if site_id is None:
            self.abort(503, 'Database not initialized')

        self.source_site = None
        self.uid = None
        self.origin = None

        # If user is attempting to log in through `/login`, ignore Auth here:
        # In future updates, move login and logout handlers to class that overrides this init
        if self.request.path == '/api/login':
            self.source_site = site_id
            return

        try:
            # TODO: This should be taken out of base.RequestHandler so `handle_exception()`
            # can properly catch exceptions raised by this logic as well as uninteded exceptions
            # For now, wrap in a try/catch to prevent stack traces from getting to the client
            # For more info see scitran/core #733

            self.initialization_auth(site_id)

        except Exception as e: # pylint: disable=broad-except
            self.handle_exception(e, self.app.debug)


    def initialize(self, request, response):
        super(RequestHandler, self).initialize(request, response)
        request.logger.info("Initialized request")
{'fraction_non_alphanumeric': 0.07378729218856753, 'fraction_numerical': 0.00614894101571396, 'mean_word_length': 3.0970149253731343, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2305140', 'n_tokens_mistral': 1149, 'n_tokens_neox': 1119, 'n_words': 391}