<commit_before>from __future__ import absolute_import
from collections import defaultdict

from corehq.blobs import Error as BlobError
from corehq.form_processor.backends.sql.dbaccessors import LedgerAccessorSQL, CaseAccessorSQL
from corehq.form_processor.exceptions import CaseNotFound, XFormNotFound, LedgerValueNotFound
from corehq.form_processor.interfaces.dbaccessors import FormAccessors, CaseAccessors
from corehq.form_processor.utils.general import should_use_sql_backend
from corehq.util.quickcache import quickcache
from pillowtop.dao.django import DjangoDocumentStore
from pillowtop.dao.exceptions import DocumentNotFoundError
from pillowtop.dao.interface import ReadOnlyDocumentStore


class ReadonlyFormDocumentStore(ReadOnlyDocumentStore):

    def __init__(self, domain, xmlns=None):
        self.domain = domain
        self.form_accessors = FormAccessors(domain=domain)
        self.xmlns = xmlns

    def get_document(self, doc_id):
        try:
            return self.form_accessors.get_form(doc_id).to_json(include_attachments=True)
        except (XFormNotFound, BlobError) as e:
            raise DocumentNotFoundError(e)

    def iter_document_ids(self, last_id=None):
        # todo: support last_id
        return iter(self.form_accessors.iter_form_ids_by_xmlns(self.xmlns))

    def iter_documents(self, ids):
        for wrapped_form in self.form_accessors.iter_forms(ids):
            yield wrapped_form.to_json()


class ReadonlyCaseDocumentStore(ReadOnlyDocumentStore):

    def __init__(self, domain, case_type=None):
        self.domain = domain
        self.case_accessors = CaseAccessors(domain=domain)
        self.case_type = case_type

    def get_document(self, doc_id):<commit_msg>Fixed call to couch document store.<commit_after>from __future__ import absolute_import
from collections import defaultdict

from corehq.blobs import Error as BlobError
from corehq.form_processor.backends.sql.dbaccessors import LedgerAccessorSQL, CaseAccessorSQL
from corehq.form_processor.exceptions import CaseNotFound, XFormNotFound, LedgerValueNotFound
from corehq.form_processor.interfaces.dbaccessors import FormAccessors, CaseAccessors
from corehq.form_processor.models import XFormInstanceSQL
from corehq.form_processor.utils.general import should_use_sql_backend
from corehq.util.quickcache import quickcache
from pillowtop.dao.django import DjangoDocumentStore
from pillowtop.dao.exceptions import DocumentNotFoundError
from pillowtop.dao.interface import ReadOnlyDocumentStore


class ReadonlyFormDocumentStore(ReadOnlyDocumentStore):

    def __init__(self, domain, xmlns=None):
        self.domain = domain
        self.form_accessors = FormAccessors(domain=domain)
        self.xmlns = xmlns

    def get_document(self, doc_id):
        try:
            form = self.form_accessors.get_form(doc_id)
            if isinstance(form, XFormInstanceSQL):
                return form.to_json(include_attachments=True)
            else:
                return form.to_json()
        except (XFormNotFound, BlobError) as e:
            raise DocumentNotFoundError(e)

    def iter_document_ids(self, last_id=None):
        # todo: support last_id
        return iter(self.form_accessors.iter_form_ids_by_xmlns(self.xmlns))

    def iter_documents(self, ids):
        for wrapped_form in self.form_accessors.iter_forms(ids):
            yield wrapped_form.to_json()


class ReadonlyCaseDocumentStore(ReadOnlyDocumentStore):

    def __init__(self, domain, case_type=None):
        self.domain = domain
        self.case_accessors = CaseAccessors(domain=domain)
        self.case_type = case_type

    def get_document(self, doc_id):
{'fraction_non_alphanumeric': 0.06508066721356302, 'fraction_numerical': 0.0, 'mean_word_length': 4.263309352517986, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, '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': '3299426', 'n_tokens_mistral': 1051, 'n_tokens_neox': 1034, 'n_words': 230}