<commit_before>"""
mingprovider Module

This contains the class which allows sprox to interface with any database.

Copyright &copy 2009 <NAME>
Original Version by <NAME> 2009
Released under MIT license.
"""
from sprox.iprovider import IProvider
from sprox.util import timestamp
import datetime, inspect

from ming.orm import mapper, FieldProperty, RelationProperty
from ming.orm.declarative import MappedClass
from ming.orm.property import OneToManyJoin, ManyToOneJoin
from ming import schema as S
from pymongo.objectid import ObjectId
import bson

from widgetselector import MingWidgetSelector
from validatorselector import MingValidatorSelector
from pymongo import ASCENDING, DESCENDING

class MingProvider(IProvider):

    default_widget_selector_type = MingWidgetSelector
    default_validator_selector_type = MingValidatorSelector

    def __init__(self, hint, **hints):
        self.session = hint

    def get_field(self, entity, name):
        """Get a field with the given field name."""
        return mapper(entity).property_index[name]

    def get_fields(self, entity):
        """Get all of the fields for a given entity."""
        if inspect.isfunction(entity):
            entity = entity()
        return [prop.name for prop in mapper(entity).properties if isinstance(prop, FieldProperty) or isinstance(prop, RelationProperty)]

    @property
    def _entities(self):
        entities = getattr(self, '__entities', None)
        if entities is None:
            entities = dict(((m.mapped_class.__name__, m) for m in MappedClass._registry.itervalues()))
            self.__entities = entities
        return entities
    
    def get_entity(self, name):
        """Get an entity with the given name."""
        return self._entities[name].mapped_class

    def get_entities(self):
        """Get all entities available for this provider."""
        return self._entities.iterkeys()

    def get_primary_fields(self, entity):
        """Get the fields in the entity which uniquely identifies a record."""
        return [self.get_primary_field(entity)]

    def get_primary_field(self, entity):
        """Get the single primary field for an entity"""
        return '_id'

    def _get_meta(self, entity, field_name, metaprop):
        """Returns the value of the given sprox meta property for the field."""<commit_msg>This permits to support subclasses of ORMPRoperty declared by the user<commit_after>"""
mingprovider Module

This contains the class which allows sprox to interface with any database.

Copyright &copy 2009 <NAME>
Original Version by Jorge Vargas 2009
Released under MIT license.
"""
from sprox.iprovider import IProvider
from sprox.util import timestamp
import datetime, inspect

from ming.orm import mapper, ForeignIdProperty, FieldProperty, RelationProperty
from ming.orm.declarative import MappedClass
from ming.orm.property import OneToManyJoin, ManyToOneJoin, ORMProperty
from ming import schema as S
from pymongo.objectid import ObjectId
import bson

from widgetselector import MingWidgetSelector
from validatorselector import MingValidatorSelector
from pymongo import ASCENDING, DESCENDING

class MingProvider(IProvider):

    default_widget_selector_type = MingWidgetSelector
    default_validator_selector_type = MingValidatorSelector

    def __init__(self, hint, **hints):
        self.session = hint

    def get_field(self, entity, name):
        """Get a field with the given field name."""
        return mapper(entity).property_index[name]

    def get_fields(self, entity):
        """Get all of the fields for a given entity."""
        if inspect.isfunction(entity):
            entity = entity()
        return [prop.name for prop in mapper(entity).properties if isinstance(prop, ORMProperty) and \
                                                                   not isinstance(prop, ForeignIdProperty)]

    @property
    def _entities(self):
        entities = getattr(self, '__entities', None)
        if entities is None:
            entities = dict(((m.mapped_class.__name__, m) for m in MappedClass._registry.itervalues()))
            self.__entities = entities
        return entities
    
    def get_entity(self, name):
        """Get an entity with the given name."""
        return self._entities[name].mapped_class

    def get_entities(self):
        """Get all entities available for this provider."""
        return self._entities.iterkeys()

    def get_primary_fields(self, entity):
        """Get the fields in the entity which uniquely identifies a record."""
        return [self.get_primary_field(entity)]

    def get_primary_field(self, entity):
        """Get the single primary field for an entity"""
        return '_id'

    def _get_meta(self, entity, field_name, metaprop):
        """Returns the value of the given sprox meta property for the field."""
{'fraction_non_alphanumeric': 0.07782824112303881, 'fraction_numerical': 0.0033030553261767133, 'mean_word_length': 3.396551724137931, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7017807', 'n_tokens_mistral': 1296, 'n_tokens_neox': 1244, 'n_words': 461}