#! usr/bin/python
# coding=utf-8

# Copyright 2014 Baidu, Inc.
#
# 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.


"""
This module provides a client class for infinite.
"""
import copy
import logging
import warnings

import baidubce
from baidubce import utils
from baidubce import compat
from baidubce.auth import bce_v1_signer
from baidubce.bce_base_client import BceBaseClient
from baidubce.http import bce_http_client
from baidubce.http import handler
from baidubce.http import http_headers
from baidubce.http import http_content_types
from baidubce.http import http_methods
from baidubce.utils import required
from baidubce.services import infinite
import http.client
from baidubce.exception import BceClientError
from baidubce.exception import BceServerError
from baidubce.bce_client_configuration import BceClientConfiguration
import uuid

_logger = logging.getLogger(__name__)

def _parse_http_response(http_response, response):
    if http_response.status / 100 == http.client.CONTINUE / 100:
        raise BceClientError('Can not handle 1xx http status code')
    if http_response.status / 100 == http.client.OK / 100:
        body = http_response.read()
        if body:
            response.__dict__.update({'Body': body})
        http_response.close()
        return True
    bse = BceServerError(http_response.reason, request_id=response.metadata.bce_request_id)
    bse.status_code = http_response.status
    http_response.close()
    raise bse


class InfiniteClient(BceBaseClient):
    """
    Infinite sdk client
    """
    def __init__(self, config=None):
        BceBaseClient.__init__(self, config)

    def predict(self, endpoint_name, body,
            variant_name=None, content_type='application/json', config=None,
            interface='predict'):
        """
        predict

        :param endpoint_name: endpoint name
        :type endpoint_name: string

        :param body: request data
        :type body: binary string or dict