Exemple #1
0
async def start_learning(request):
    query = request.url_data
    if not query['algo'] or query['algo'] not in algorithm_opts:
        return wsgi.WsgiResponse(
            400, json.dumps({'error': 'unknown algorithm type'}, indent=4))

    num_instances = 2
    if 'instances' in query:
        num_instances = int(query['instances'])

    activation = 'relu'
    if 'activation' in query:
        activation = query['activation']

    # run managers
    if query['algo'] in ['svm', 'all']:
        await pulsar.send('svm_manager_actor', 'run_svm_learning', {})
    if query['algo'] in ['bayes', 'all']:
        await pulsar.send('bayes_manager_actor', 'run_bayes_learning', {})
    if query['algo'] in ['network', 'all']:
        await pulsar.send('network_manager_actor', 'run_network_learning', {
            'instances': num_instances,
            'activation': activation
        })

    info = await pulsar.send('arbiter', 'info')

    data = {
        'arbiter_info': info,
    }
    return wsgi.WsgiResponse(200, json.dumps(data, indent=4))
Exemple #2
0
 def test_max_age_expiration(self):
     "Cookie will expire if max_age is provided"
     response = wsgi.WsgiResponse()
     response.set_cookie('max_age', max_age=10)
     max_age_cookie = response.cookies['max_age']
     self.assertEqual(max_age_cookie['max-age'], 10)
     self.assertEqual(max_age_cookie['expires'], http_date(time.time()+10))
Exemple #3
0
 def testForCoverage(self):
     r = wsgi.WsgiResponse(environ={'PATH_INFO': 'bla/'})
     self.assertEqual(r.path, 'bla/')
     self.assertEqual(r.connection, None)
     self.assertEqual(r.content, ())
     self.assertEqual(list(r), [])
     self.assertRaises(RuntimeError, list, r)
Exemple #4
0
 def test_far_expiration(self):
     "Cookie will expire when an distant expiration time is provided"
     response = wsgi.WsgiResponse()
     response.set_cookie('datetime', expires=datetime(2028, 1, 1, 4, 5, 6))
     datetime_cookie = response.cookies['datetime']
     self.assertEqual(datetime_cookie['expires'],
                      'Sat, 01 Jan 2028 04:05:06 GMT')
Exemple #5
0
 def test_httponly_cookie(self):
     response = wsgi.WsgiResponse()
     response.set_cookie('example', httponly=True)
     example_cookie = response.cookies['example']
     # A compat cookie may be in use -- check that it has worked
     # both as an output string, and using the cookie attributes
     self.assertTrue('; httponly' in str(example_cookie).lower())
     self.assertTrue(example_cookie['httponly'])
Exemple #6
0
async def data_info(request):
    global arbiter

    info = await pulsar.send('data_provider', 'data_provider_info')
    data = {
        'data_provider_info': info,
    }
    return wsgi.WsgiResponse(200, json.dumps(data, indent=4))
Exemple #7
0
async def stop_manager(request):
    global arbiter

    info = await pulsar.get_actor().send(arbiter, 'info')
    data = {
        'arbiter_info': info,
    }
    return wsgi.WsgiResponse(200, json.dumps(data, indent=4))
Exemple #8
0
 def testResponse500(self):
     r = wsgi.WsgiResponse(500, content=b'A critical error occurred')
     self.assertEqual(r.status_code, 500)
     self.assertEqual(r.status, '500 Internal Server Error')
     self.assertEqual(r.content, (b'A critical error occurred',))
     self.assertFalse(r.is_streamed())
     self.assertFalse(r.started)
     self.assertEqual(list(r), [b'A critical error occurred'])
     self.assertTrue(r.started)
Exemple #9
0
async def stop_learning(request):
    query = request.url_data
    if not query['algo'] or query['algo'] not in algorithm_opts:
        return wsgi.WsgiResponse(
            400, json.dumps({'error': 'unknown algorithm type'}, indent=4))

    # kill manager actors
    if query['algo'] in ['svm', 'all']:
        await pulsar.send('svm_manager_actor', 'kill_svm_instances')
    if query['algo'] in ['bayes', 'all']:
        await pulsar.send('bayes_manager_actor', 'kill_bayes_instances')
    if query['algo'] in ['network', 'all']:
        await pulsar.send('network_manager_actor', 'kill_network_instances')

    info = await pulsar.send('arbiter', 'info')
    data = {
        'arbiter_info': info,
    }
    return wsgi.WsgiResponse(200, json.dumps(data, indent=4))
Exemple #10
0
 def testResponse200(self):
     r = wsgi.WsgiResponse(200)
     self.assertEqual(r.status_code, 200)
     self.assertEqual(r.status, '200 OK')
     self.assertEqual(r.content, ())
     self.assertFalse(r.is_streamed())
     self.assertFalse(r.started)
     self.assertEqual(list(r), [])
     self.assertTrue(r.started)
     self.assertEqual(str(r), r.status)
     self.assertTrue(repr(r))
Exemple #11
0
 def error(self, exc):
     if not self._started:
         request = wsgi.WsgiRequest(self.environ)
         content_type = request.content_types.best_match(
             ('text/html', 'text/plain'))
         uri = self.environ['RAW_URI']
         msg = 'Could not find %s' % uri
         logger.info(msg=msg)
         if content_type == 'text/html':
             html = wsgi.HtmlDocument(title=msg)
             html.body.append('<h1>%s</h1>' % msg)
             data = html.render()
             resp = wsgi.WsgiResponse(504, data, content_type='text/html')
         elif content_type == 'text/plain':
             resp = wsgi.WsgiResponse(504, msg, content_type='text/html')
         else:
             resp = wsgi.WsgiResponse(504, '')
         self.start_response(resp.status, resp.get_headers())
         self._done = True
         self.queue.put_nowait(resp.content[0])
Exemple #12
0
 def testStreamed(self):
     stream = ('line {0}\n'.format(l+1) for l in range(10))
     r = wsgi.WsgiResponse(content=stream)
     self.assertEqual(r.status_code, 200)
     self.assertEqual(r.status, '200 OK')
     self.assertEqual(r.content, stream)
     self.assertTrue(r.is_streamed)
     data = []
     for l, a in enumerate(r):
         data.append(a)
         self.assertTrue(r.started)
         self.assertEqual(a, ('line {0}\n'.format(l+1)).encode('utf-8'))
     self.assertEqual(len(data), 10)
Exemple #13
0
 def error(self, failure):
     '''Handle a failure.'''
     if not self._done:
         uri = self.environ['RAW_URI']
         msg = 'Oops! Could not find %s' % uri
         html = wsgi.HtmlDocument(title=msg)
         html.body.append('<h1>%s</h1>' % msg)
         data = html.render()
         resp = wsgi.WsgiResponse(504, data, content_type='text/html')
         self.start_response(resp.status, resp.get_headers(),
                             failure.exc_info)
         self._done = True
         self.queue.put(resp.content[0])
Exemple #14
0
 def testStreamed(self):
     stream = (b'line %x\n' % (l+1) for l in range(10))
     r = wsgi.WsgiResponse(content=stream)
     self.assertEqual(r.status_code, 200)
     self.assertEqual(r.status, '200 OK')
     self.assertEqual(r.content, stream)
     self.assertTrue(r.is_streamed())
     data = []
     for l, a in enumerate(r, 1):
         data.append(a)
         self.assertTrue(r.started)
         self.assertEqual(a, b'line %x\n' % l)
     self.assertEqual(len(data), 10)
Exemple #15
0
async def get_progress(request):
    global arbiter, svm_manager_actor, bayes_manager_actor, network_manager_actor

    query = request.url_data
    if not query['algo'] or query['algo'] not in algorithm_opts:
        return wsgi.WsgiResponse(
            400, json.dumps({'error': 'unknown algorithm type'}, indent=4))

    progress = {}

    # run managers
    if query['algo'] in ['svm', 'all']:
        progress['svm'] = await pulsar.send('svm_manager_actor',
                                            'get_svm_progress')
    if query['algo'] in ['bayes', 'all']:
        progress['bayes'] = await pulsar.send('bayes_manager_actor',
                                              'get_bayes_progress')
    if query['algo'] in ['network', 'all']:
        progress['network'] = await pulsar.send('network_manager_actor',
                                                'get_network_progress')

    data = progress
    return wsgi.WsgiResponse(200, json.dumps(data, indent=4))
Exemple #16
0
async def data_sample(request):
    query = request.url_data

    # default
    input_format = 'hot_vector'
    output_format = 'categorical'

    if 'input_format' in query:
        input_format = query['input_format']
    if 'output_format' in query:
        output_format = query['output_format']

    (X_data, Y_data) = await pulsar.send('data_provider', 'get_data_command', {
        'input_format': input_format,
        'output_format': output_format
    })

    data = {
        'length': len(X_data),
        'X_data': str(X_data),
        'Y_data': str(Y_data),
    }
    return wsgi.WsgiResponse(200, json.dumps(data, indent=4))
Exemple #17
0
 def testCookies(self):
     response = wsgi.WsgiResponse()
     expires = datetime.now() + timedelta(seconds=3600)
     response.set_cookie('bla', expires=expires)
     self.assertTrue('bla' in response.cookies)
Exemple #18
0
 def testForCoverage(self):
     r = wsgi.WsgiResponse()
     self.assertEqual(r.content, ())
     self.assertEqual(list(r), [])
     self.assertRaises(RuntimeError, list, r)
Exemple #19
0
async def test_joke(request):

    joke = str(request.url_data['joke'])

    category = await pulsar.send('network_manager_actor', 'test_joke', joke)
    return wsgi.WsgiResponse(200, json.dumps({'category': category}, indent=4))
Exemple #20
0
 def test_headers(self):
     response = wsgi.WsgiResponse(200)
     response['content-type'] = 'text/plain'
     self.assertTrue('content-type' in response)
     self.assertTrue(response.has_header('content-type'))
     self.assertEqual(response['content-type'], 'text/plain')
Exemple #21
0
 def testDeleteCookie(self):
     response = wsgi.WsgiResponse()
     response.delete_cookie('bla')
     self.assertTrue('bla' in response.cookies)