def execute(self, request: HttpRequest) -> HttpResponse:
     logger.debug("execute request;; request: %s; method: %s ;url: %s",
                  request.__class__, request.method, request.url)
     logger.debug("verify request;; request: %s; method: %s ;url: %s",
                  request.__class__, request.method, request.url)
     request.verify()
     logger.debug(
         "request verify passed;; request: %s; method: %s ;url: %s",
         request.__class__, request.method, request.url)
     headers = self._headers
     logger.debug("send http request: %s", request)
     if request.auth() > 0 and (StringUtils.is_blank(self._token)
                                or self._token_expire_time < time.time()):
         raise TokenInvalid(LOGIN_NEEDED, "login first")
     if request.auth() > 0:
         headers['Cookie'] = 'access_token=%s' % self._token
     try:
         response_str = self._do_execute(request.url,
                                         self._prepare_param(request),
                                         headers, self._config.timeout,
                                         request.method)
     except Exception as e:
         logger.error("http excepiton;; %s", e)
         raise ApiExecuteException(API_EXCEPTION, "http exception" + str(e))
     return self._parse_response(response_str)
 def test_is_none_blank(self):
     self.assertFalse(StringUtils.is_none_blank(None))
     self.assertFalse(StringUtils.is_none_blank(None, "foo"))
     self.assertFalse(StringUtils.is_none_blank("", "foo"))
     self.assertFalse(StringUtils.is_none_blank("bob", None))
     self.assertFalse(StringUtils.is_none_blank("  bob  ", None))
     self.assertFalse(StringUtils.is_none_blank(" ", "bar"))
     self.assertTrue(StringUtils.is_none_blank("foo", "bar"))
 def test_is_any_empty(self):
     self.assertTrue(StringUtils.is_any_empty(None))
     self.assertTrue(StringUtils.is_any_empty(None, "foo"))
     self.assertTrue(StringUtils.is_any_empty("", "foo"))
     self.assertTrue(StringUtils.is_any_empty("bob", None))
     self.assertTrue(StringUtils.is_any_empty("  bob  ", None))
     self.assertFalse(StringUtils.is_any_empty(" ", "bar"))
     self.assertFalse(StringUtils.is_any_empty("foo", "bar"))
 def _parse_response(self, response_str: str) -> HttpResponse:
     dic = json.loads(response_str)
     # todo 自动踢出
     if 'result_code' not in dic \
             or 'msg' not in dic \
             or 'result_data' not in dic:
         raise ApiExecuteException(API_EXCEPTION, 'response result invalid')
     response = HttpResponse()
     response.data = dic.get('result_data')
     response.result_code = dic.get('result_code')
     response.message = StringUtils.default_string(dic.get('msg'))
     response.result_str = response_str
     return response
Exemple #5
0
 def verify(self):
     if StringUtils.is_any_blank(self.account, self.key, self.sign_type,
                                 self.snb_server, self.snb_port,
                                 self._schema):
         logger.error(
             "configuration is invalid;; some necessary param is blank")
         raise ConfigException(CONFIGURATION_IS_INVALID,
                               "configuration is invalid")
     if self.timeout <= 0:
         logger.error(
             "configuration is invalid;; timeout not set or invalid")
         raise ConfigException(CONFIGURATION_IS_INVALID,
                               "configuration is invalid")
Exemple #6
0
 def verify(self) -> bool:
     return StringUtils.is_none_blank(self._account_id, self._secret_key)
Exemple #7
0
 def verify(self) -> bool:
     return StringUtils.is_not_blank(self._symbol)
Exemple #8
0
 def verify(self) -> bool:
     return StringUtils.is_not_blank(self._account_id)
Exemple #9
0
 def verify(self) -> bool:
     return StringUtils.is_none_blank(self._order_id, self._origin_order_id,
                                      self._account_id)
Exemple #10
0
 def verify(self) -> bool:
     if StringUtils.is_blank(self._order_id):
         logger.error("order id cannot by blank;; order_id: %s",
                      self._order_id)
         raise InvalidParamException(INVALID_ORDER_ID, "INVALID ORDER ID")
     return StringUtils.is_none_blank(self._account_id, self._order_id)
Exemple #11
0
 def verify(self):
     if StringUtils.is_any_blank(self.account, self.key, self.sign_type, self.snb_server, self.snb_port,
                                 self._schema):
         raise ConfigException(CONFIGURATION_IS_INVALID, "configuration is invalid")
     if self.timeout <= 0:
         raise ConfigException(CONFIGURATION_IS_INVALID, "configuration is invalid")
 def test_default_string(self):
     self.assertEquals("", StringUtils.default_string(None))
     self.assertEquals("", StringUtils.default_string(""))
     self.assertEquals(" ", StringUtils.default_string(" "))
     self.assertEquals("bat", StringUtils.default_string("bat"))
 def test_is_empty(self):
     self.assertTrue(StringUtils.is_empty(None))
     self.assertTrue(StringUtils.is_empty(""))
     self.assertFalse(StringUtils.is_empty(" "))
     self.assertFalse(StringUtils.is_empty("bob"))
     self.assertFalse(StringUtils.is_empty("  bob  "))
 def test_is_not_blank(self):
     self.assertFalse(StringUtils.is_not_blank(None))
     self.assertFalse(StringUtils.is_not_blank(""))
     self.assertFalse(StringUtils.is_not_blank(" "))
     self.assertTrue(StringUtils.is_not_blank("bob"))
     self.assertTrue(StringUtils.is_not_blank("  bob  "))