<commit_before>import base64
import ConfigParser
import datetime
import httplib
import json
import logging
import MySQLdb
import os
import urllib2

from dirq.queue import Queue, QueueError
from rest_framework.pagination import PaginationSerializer
from django.conf import settings
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from rest_framework.response import Response
from rest_framework.views import APIView


class CloudRecordSummaryView(APIView):
    """
    Retrieve Cloud Accounting Summaries.

    .../cloud/record/summary?Group=<group_name>&from=<date_from>&to=<date_to>

    Will return the summary for group_name at all services,
    between date_from and date_to as daily summaries

    .../cloud/record/summary?service=<service_name>&from=<date_from>&to=<date_to>

    Will return the summary for service_name at all groups,
    between date_from and date_to as daily summaries

    .../cloud/record/summary?from=<date_from>
    Will give summary for whole infrastructure from <data> to now
    """

    def get(self, request, format=None):
        """
        Retrieve Cloud Accounting Summaries.

        .../cloud/record/summary?Group=<group_name>&from=<date_from>&to=<date_to>

        Will return the summary for group_name at all services,
        between date_from and date_to as daily summaries

        .../cloud/record/summary?service=<service_name>&from=<date_from>&to=<date_to>

        Will return the summary for service_name at all groups,
        between date_from and date_to as daily summaries

        .../cloud/record/summary?from=<date_from>
        Will give summary for whole infrastructure from <data> to now
        """
        logger = logging.getLogger(__name__)

        try:
            client_token = self._request_to_token(request)
        except KeyError:
            logger.error("No AUTHORIZATION header provided, authentication failed.")
            return Response(status=401)
        except IndexError:
            logger.error("AUTHORIZATION header provided, but not of expected form.")
            logger.error(request.META['HTTP_AUTHORIZATION'])
            return Response(status=401)

        logger.info("%s Authenticated", client_token)

        try:
            client_id = self._token_to_id(client_token)
        except urllib2.HTTPError, e:
            logger.error('HTTPError = ' + str(e.code))
            logger.error('Could not Authorize.')
            return Response(status=401)
        except urllib2.URLError, e:
            logger.error('URLError = ' + str(e.reason))
            logger.error('Could not Authorize.')
            return Response(status=401)
        except httplib.HTTPException:
            logger.error('HTTPException')
            logger.error('Could not Authorize.')
            return Response(status=401)
        except KeyError:
            logger.error("No client id in IAM response, likely token has expired")
            return Response(status=401)        

        logger.info("Token identifed as %s", client_id)

        if not self._is_client_authorized(client_id):
            logger.error("%s does not have permission to view summaries", client_id)
            return Response(status=403)

        logger.info("%s Authorized.", client_id)
 
        # parse query parameters
        (group_name,
         service_name,
         start_date,
         end_date) = self._parse_query_parameters(request)

        if start_date is None:
            # querying without a from is not supported
            return Response(status=501)
<commit_msg>Change the level that this is logged at<commit_after>import base64
import ConfigParser
import datetime
import httplib
import json
import logging
import MySQLdb
import os
import urllib2

from dirq.queue import Queue, QueueError
from rest_framework.pagination import PaginationSerializer
from django.conf import settings
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from rest_framework.response import Response
from rest_framework.views import APIView


class CloudRecordSummaryView(APIView):
    """
    Retrieve Cloud Accounting Summaries.

    .../cloud/record/summary?Group=<group_name>&from=<date_from>&to=<date_to>

    Will return the summary for group_name at all services,
    between date_from and date_to as daily summaries

    .../cloud/record/summary?service=<service_name>&from=<date_from>&to=<date_to>

    Will return the summary for service_name at all groups,
    between date_from and date_to as daily summaries

    .../cloud/record/summary?from=<date_from>
    Will give summary for whole infrastructure from <data> to now
    """

    def get(self, request, format=None):
        """
        Retrieve Cloud Accounting Summaries.

        .../cloud/record/summary?Group=<group_name>&from=<date_from>&to=<date_to>

        Will return the summary for group_name at all services,
        between date_from and date_to as daily summaries

        .../cloud/record/summary?service=<service_name>&from=<date_from>&to=<date_to>

        Will return the summary for service_name at all groups,
        between date_from and date_to as daily summaries

        .../cloud/record/summary?from=<date_from>
        Will give summary for whole infrastructure from <data> to now
        """
        logger = logging.getLogger(__name__)

        try:
            client_token = self._request_to_token(request)
        except KeyError:
            logger.error("No AUTHORIZATION header provided, authentication failed.")
            return Response(status=401)
        except IndexError:
            logger.error("AUTHORIZATION header provided, but not of expected form.")
            logger.error(request.META['HTTP_AUTHORIZATION'])
            return Response(status=401)

        logger.info("%s Authenticated", client_token)

        try:
            client_id = self._token_to_id(client_token)
        except urllib2.HTTPError, e:
            logger.error('HTTPError = ' + str(e.code))
            logger.error('Could not Authorize.')
            return Response(status=401)
        except urllib2.URLError, e:
            logger.error('URLError = ' + str(e.reason))
            logger.error('Could not Authorize.')
            return Response(status=401)
        except httplib.HTTPException:
            logger.error('HTTPException')
            logger.error('Could not Authorize.')
            return Response(status=401)
        except KeyError:
            logger.error("No client id in IAM response, likely token has expired")
            return Response(status=401)        

        logger.debug("Token identifed as %s", client_id)

        if not self._is_client_authorized(client_id):
            logger.error("%s does not have permission to view summaries", client_id)
            return Response(status=403)

        logger.info("%s Authorized.", client_id)
 
        # parse query parameters
        (group_name,
         service_name,
         start_date,
         end_date) = self._parse_query_parameters(request)

        if start_date is None:
            # querying without a from is not supported
            return Response(status=501)

{'fraction_non_alphanumeric': 0.08411345535839039, 'fraction_numerical': 0.008103954170741931, 'mean_word_length': 2.7673684210526317, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, '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': '4421744', 'n_tokens_mistral': 1996, 'n_tokens_neox': 1911, 'n_words': 543}