Esempio n. 1
0
    def serve(self, port=8000, no_documentation=False):
        '''Runs the basic hug development server against this API'''
        if no_documentation:
            api = server(self.module, sink=None)
        else:
            api = server(self.module)

        print(INTRO)
        httpd = make_server('', port, api)
        print("Serving on port {0}...".format(port))
        httpd.serve_forever()
Esempio n. 2
0
    def serve(self, port=8000, no_documentation=False):
        '''Runs the basic hug development server against this API'''
        if no_documentation:
            api = server(self.module, sink=None)
        else:
            api = server(self.module)

        print(INTRO)
        httpd = make_server('', port, api)
        print("Serving on port {0}...".format(port))
        httpd.serve_forever()
Esempio n. 3
0
def call(method, api_module, url, body='', headers=None, **params):
    '''Simulates a round-trip call against the given api_module / url'''
    api = server(api_module)
    response = StartResponseMock()
    if not isinstance(body, str):
        body = output_format.json(body)
        headers = {} if headers is None else headers
        headers['content-type'] = 'application/json'

    result = api(
        create_environ(path=url,
                       method=method,
                       headers=headers,
                       query_string=urlencode(params),
                       body=body), response)
    if result:
        try:
            response.data = result[0].decode('utf8')
        except TypeError:
            response.data = []
            for chunk in result:
                response.data.append(chunk.decode('utf8'))
            response.data = "".join(response.data)
        except UnicodeDecodeError:
            response.data = result[0]
        response.content_type = response.headers_dict['content-type']
        if response.content_type == 'application/json':
            response.data = json.loads(response.data)

    return response
Esempio n. 4
0
def call(method, api_module, url, body="", headers=None, **params):
    """Simulates a round-trip call against the given api_module / url"""
    api = server(api_module)
    response = StartResponseMock()
    if not isinstance(body, str):
        body = output_format.json(body)
        headers = {} if headers is None else headers
        headers["content-type"] = "application/json"

    result = api(
        create_environ(path=url, method=method, headers=headers, query_string=urlencode(params), body=body), response
    )
    if result:
        try:
            response.data = result[0].decode("utf8")
        except TypeError:
            response.data = []
            for chunk in result:
                response.data.append(chunk.decode("utf8"))
            response.data = "".join(response.data)
        response.content_type = response.headers_dict["content-type"]
        if response.content_type == "application/json":
            response.data = json.loads(response.data)

    return response
Esempio n. 5
0
File: test.py Progetto: jean/hug
def call(method, api_module, url, body='', headers=None, **params):
    '''Simulates a round-trip call against the given api_module / url'''
    api = server(api_module)
    response = StartResponseMock()
    if not isinstance(body, str):
        body = output_format.json(body)
        headers = {} if headers is None else headers
        headers['content-type'] = 'application/json'

    result = api(create_environ(path=url, method=method, headers=headers, query_string=urlencode(params), body=body),
                 response)
    if result:
        response.data = result[0].decode('utf8')
        response.content_type = response.headers_dict['content-type']
        if response.content_type == 'application/json':
            response.data = json.loads(response.data)

    return response
Esempio n. 6
0
 def api_auto_instantiate(*kargs, **kwargs):
     if not hasattr(module, '__hug_serving__'):
         module.__hug_wsgi__ = server(module)
         module.__hug_serving__ = True
     return module.__hug_wsgi__(*kargs, **kwargs)
Esempio n. 7
0
 def api_auto_instantiate(*kargs, **kwargs):
     module.__hug_wsgi__ = server(module)
     return module.__hug_wsgi__(*kargs, **kwargs)
Esempio n. 8
0
 def api_auto_instantiate(*kargs, **kwargs):
     if not hasattr(module, '__hug_serving__'):
         module.__hug_wsgi__ = server(module)
         module.__hug_serving__ = True
     return module.__hug_wsgi__(*kargs, **kwargs)
Esempio n. 9
0
 def api_auto_instantiate(*kargs, **kwargs):
     module.__hug_wsgi__ = server(module)
     return module.__hug_wsgi__(*kargs, **kwargs)