<commit_before># Copyright 2015 HuaWei Technologies.
#
#    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.

from neutron_lib import exceptions as n_exc
from oslo_log import log
from oslo_utils import timeutils
from sqlalchemy import event
from sqlalchemy import exc as sql_exc
from sqlalchemy.orm import session as se

from neutron._i18n import _LW
from neutron.db import standard_attr

LOG = log.getLogger(__name__)

CHANGED_SINCE = 'changed_since'


class TimeStamp_db_mixin(object):
    """Mixin class to add Time Stamp methods."""

    ISO8601_TIME_FORMAT = '%Y-%m-%dT%H:%M:%S'

    def _change_since_result_filter_hook(self, query, filters):
        # this block is for change_since query
        # we get the changed_since string from filters.
        # And translate it from string to datetime type.
        # Then compare with the timestamp in db which has
        # datetime type.
        values = filters and filters.get(CHANGED_SINCE, [])
        if not values:
            return query
        data = filters[CHANGED_SINCE][0]
        try:
            changed_since_string = timeutils.parse_isotime(data)
        except Exception:
            msg = _LW("The input %s must be in the "
                      "following format: YYYY-MM-DDTHH:MM:SSZ") % CHANGED_SINCE
            raise n_exc.InvalidInput(error_message=msg)
        changed_since = (timeutils.
                         normalize_time(changed_since_string))
        target_model_class = list(query._mapper_adapter_map.keys())[0]
        query = query.join(standard_attr.StandardAttribute,
                           target_model_class.standard_attr_id ==
                           standard_attr.StandardAttribute.id).filter(
                           standard_attr.StandardAttribute.updated_at
                           >= changed_since)
        return query

    def update_timestamp(self, session, context, instances):
        objs_list = session.new.union(session.dirty)

        while objs_list:
            obj = objs_list.pop()<commit_msg>Use Query.column_descriptions instead of private property<commit_after># Copyright 2015 HuaWei Technologies.
#
#    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.

from neutron_lib import exceptions as n_exc
from oslo_log import log
from oslo_utils import timeutils
from sqlalchemy import event
from sqlalchemy import exc as sql_exc
from sqlalchemy.orm import session as se

from neutron._i18n import _LW
from neutron.db import standard_attr

LOG = log.getLogger(__name__)

CHANGED_SINCE = 'changed_since'


class TimeStamp_db_mixin(object):
    """Mixin class to add Time Stamp methods."""

    ISO8601_TIME_FORMAT = '%Y-%m-%dT%H:%M:%S'

    def _change_since_result_filter_hook(self, query, filters):
        # this block is for change_since query
        # we get the changed_since string from filters.
        # And translate it from string to datetime type.
        # Then compare with the timestamp in db which has
        # datetime type.
        values = filters and filters.get(CHANGED_SINCE, [])
        if not values:
            return query
        data = filters[CHANGED_SINCE][0]
        try:
            changed_since_string = timeutils.parse_isotime(data)
        except Exception:
            msg = _LW("The input %s must be in the "
                      "following format: YYYY-MM-DDTHH:MM:SSZ") % CHANGED_SINCE
            raise n_exc.InvalidInput(error_message=msg)
        changed_since = (timeutils.
                         normalize_time(changed_since_string))
        target_model_class = query.column_descriptions[0]['type']
        query = query.join(standard_attr.StandardAttribute,
                           target_model_class.standard_attr_id ==
                           standard_attr.StandardAttribute.id).filter(
                           standard_attr.StandardAttribute.updated_at
                           >= changed_since)
        return query

    def update_timestamp(self, session, context, instances):
        objs_list = session.new.union(session.dirty)

        while objs_list:
            obj = objs_list.pop()
{'fraction_non_alphanumeric': 0.06795547744581136, 'fraction_numerical': 0.006248779535247022, 'mean_word_length': 2.6274787535410766, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1777212', 'n_tokens_mistral': 1430, 'n_tokens_neox': 1379, 'n_words': 456}