<commit_before># =============================================================================
#  periscope-ps (unis)
#
#  Copyright (c) 2012-2016, Trustees of Indiana University,
#  All rights reserved.
#
#  This software may be modified and distributed under the terms of the BSD
#  license.  See the COPYING file for details.
#
#  This software was created at the Indiana University Center for Research in
#  Extreme Scale Technologies (CREST).
# =============================================================================
#!/usr/bin/env python

import json
import time
from tornado.httpclient import AsyncHTTPClient
import tornado.gen

import periscope.settings as settings
from periscope.settings import MIME
from networkresourcehandler import NetworkResourceHandler
from periscope.db import dumps_mongo


class EventsHandler(NetworkResourceHandler):
    @tornado.gen.coroutine
    def _insert(self, resources):
        resource = resources[0]
        http_client = AsyncHTTPClient()
        response = yield http_client.fetch(resource["metadata_URL"],
                                           validate_cert=False,
                                           client_cert=settings.MS_CLIENT_CERT,
                                           client_key=settings.MS_CLIENT_KEY)
        
        if response.error:
            self.send_error(400, message="metadata is not found '%s'." % response.error)
        else:
            body = json.loads(response.body)
            collections = yield self.application.db.collection_names()
            if body[self.Id] not in collections:
                self.application.get_db_layer(body[self.Id], "ts", "ts", True, resource["collection_size"])
                self.set_header("Location","%s/data/%s" % (self.request.full_url().split('?')[0], body[self.Id]))
                resource[self.timestamp] = int(time.time() * 1000000)
                resource[self.Id] = body[self.Id]
                yield self.dblayer.insert(resource, summarize = False)
            else:
                raise ValueError("event collection exists already")
            
    def _find(self, **options):
        options["query"].pop("status", None)
        if not options["query"]:
            return self.dblayer.find()
        elif self.Id in options["query"] or "$or" in options["query"]:
            return self.dblayer.find(**options)<commit_msg>Resolved issue wherein un-qualified GETs to events failed<commit_after># =============================================================================
#  periscope-ps (unis)
#
#  Copyright (c) 2012-2016, Trustees of Indiana University,
#  All rights reserved.
#
#  This software may be modified and distributed under the terms of the BSD
#  license.  See the COPYING file for details.
#
#  This software was created at the Indiana University Center for Research in
#  Extreme Scale Technologies (CREST).
# =============================================================================
#!/usr/bin/env python

import json
import time
from tornado.httpclient import AsyncHTTPClient
import tornado.gen

import periscope.settings as settings
from periscope.settings import MIME
from networkresourcehandler import NetworkResourceHandler
from periscope.db import dumps_mongo


class EventsHandler(NetworkResourceHandler):
    @tornado.gen.coroutine
    def _insert(self, resources):
        resource = resources[0]
        http_client = AsyncHTTPClient()
        response = yield http_client.fetch(resource["metadata_URL"],
                                           validate_cert=False,
                                           client_cert=settings.MS_CLIENT_CERT,
                                           client_key=settings.MS_CLIENT_KEY)
        
        if response.error:
            self.send_error(400, message="metadata is not found '%s'." % response.error)
        else:
            body = json.loads(response.body)
            collections = yield self.application.db.collection_names()
            if body[self.Id] not in collections:
                self.application.get_db_layer(body[self.Id], "ts", "ts", True, resource["collection_size"])
                self.set_header("Location","%s/data/%s" % (self.request.full_url().split('?')[0], body[self.Id]))
                resource[self.timestamp] = int(time.time() * 1000000)
                resource[self.Id] = body[self.Id]
                yield self.dblayer.insert(resource, summarize = False)
            else:
                raise ValueError("event collection exists already")
            
    def _find(self, **options):
        options["query"].pop("\\$status", None)
        if not options["query"]:
            return self.dblayer.find()
        elif self.Id in options["query"] or "$or" in options["query"]:
            return self.dblayer.find(**options)
{'fraction_non_alphanumeric': 0.1583003540928973, 'fraction_numerical': 0.0083315975838367, 'mean_word_length': 2.6684491978609626, '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': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4494654', 'n_tokens_mistral': 1249, 'n_tokens_neox': 1178, 'n_words': 318}