<commit_before>"""Tools for constructing a JSON-API from sqlalchemy models in Pyramid."""

# pylint:disable=line-too-long

import copy
import functools
import importlib
import itertools
import json
import logging
import pkgutil
import re
import sys
import types
from collections import deque, Sequence, Mapping

import jsonschema
import pyramid
from pyramid.view import (
    view_config,
    notfound_view_config,
    forbidden_view_config
)
from pyramid.renderers import JSON
from pyramid.httpexceptions import (
    exception_response,
    HTTPException,
    HTTPNotFound,
    HTTPForbidden,
    HTTPUnauthorized,
    HTTPClientError,
    HTTPBadRequest,
    HTTPConflict,
    HTTPUnsupportedMediaType,
    HTTPNotAcceptable,
    HTTPNotImplemented,
    HTTPError,
    HTTPFailedDependency,
    HTTPInternalServerError,
    status_map,
)
import sqlalchemy
from sqlalchemy.orm import load_only
from sqlalchemy.exc import DBAPIError
from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound
from sqlalchemy.orm.relationships import RelationshipProperty
from sqlalchemy.ext.declarative.api import DeclarativeMeta
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.dialects.postgresql import JSONB

import pyramid_jsonapi.endpoints
import pyramid_jsonapi.jsonapi
import pyramid_jsonapi.metadata
import pyramid_jsonapi.settings
import pyramid_jsonapi.version

__version__ = pyramid_jsonapi.version.get_version()

ONETOMANY = sqlalchemy.orm.interfaces.ONETOMANY
MANYTOMANY = sqlalchemy.orm.interfaces.MANYTOMANY
MANYTOONE = sqlalchemy.orm.interfaces.MANYTOONE


class PyramidJSONAPI():

    view_classes = {}

    def __init__(self, config, models, get_dbsession=None):
        self.config = config
        self.settings = pyramid_jsonapi.settings.Settings(config.registry.settings)
        self.models = models
        self.get_dbsession = get_dbsession
        self.endpoint_data = pyramid_jsonapi.endpoints.EndpointData(self)
        self.filter_registry = FilterRegistry()<commit_msg>add docstring for PyramidJSONAPI class.<commit_after>"""Tools for constructing a JSON-API from sqlalchemy models in Pyramid."""

# pylint:disable=line-too-long

import copy
import functools
import importlib
import itertools
import json
import logging
import pkgutil
import re
import sys
import types
from collections import deque, Sequence, Mapping

import jsonschema
import pyramid
from pyramid.view import (
    view_config,
    notfound_view_config,
    forbidden_view_config
)
from pyramid.renderers import JSON
from pyramid.httpexceptions import (
    exception_response,
    HTTPException,
    HTTPNotFound,
    HTTPForbidden,
    HTTPUnauthorized,
    HTTPClientError,
    HTTPBadRequest,
    HTTPConflict,
    HTTPUnsupportedMediaType,
    HTTPNotAcceptable,
    HTTPNotImplemented,
    HTTPError,
    HTTPFailedDependency,
    HTTPInternalServerError,
    status_map,
)
import sqlalchemy
from sqlalchemy.orm import load_only
from sqlalchemy.exc import DBAPIError
from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound
from sqlalchemy.orm.relationships import RelationshipProperty
from sqlalchemy.ext.declarative.api import DeclarativeMeta
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.dialects.postgresql import JSONB

import pyramid_jsonapi.endpoints
import pyramid_jsonapi.jsonapi
import pyramid_jsonapi.metadata
import pyramid_jsonapi.settings
import pyramid_jsonapi.version

__version__ = pyramid_jsonapi.version.get_version()

ONETOMANY = sqlalchemy.orm.interfaces.ONETOMANY
MANYTOMANY = sqlalchemy.orm.interfaces.MANYTOMANY
MANYTOONE = sqlalchemy.orm.interfaces.MANYTOONE


class PyramidJSONAPI():
    """Class encapsulating an API.

    Arguments:
        config (pyramid.config.Configurator): pyramid config object from app.
        models (module or iterable): a models module or iterable of models.

    Keyword Args:
        get_dbsession (callable): function accepting an instance of
            CollectionViewBase and returning a sqlalchemy database session.
    """

    view_classes = {}

    def __init__(self, config, models, get_dbsession=None):
        self.config = config
        self.settings = pyramid_jsonapi.settings.Settings(config.registry.settings)
        self.models = models
        self.get_dbsession = get_dbsession
        self.endpoint_data = pyramid_jsonapi.endpoints.EndpointData(self)
        self.filter_registry = FilterRegistry()
{'fraction_non_alphanumeric': 0.05746606334841629, 'fraction_numerical': 0.0, 'mean_word_length': 4.624681933842239, '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': '1047567', 'n_tokens_mistral': 1365, 'n_tokens_neox': 1276, 'n_words': 318}